axis.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
1. Soap方法定义接口
public interface SoapService {
public String getDatabaseConfiguration();
}
2. 代理执行Soap定义的方法
public class SoapInvokerHandler implements InvocationHandler {
private Call call;
public void initCall() throws ServiceException {
Service service = new Service();
call = (Call) service.createCall();
call.setTimeout(30000);
// call.addHeader(new SOAPHeaderElement("", "ClientType", "Test"));
call.setTargetEndpointAddress(String.format("http://%s/services/Test?wsdl", "127.0.0.1:8080"));
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return call.invoke(method.getName(), args);
}
}
3. 使用
public class SoapInvokerFactory {
public static SoapService getInvoker() throws ServiceException {
SoapInvokerHandler invokerHandler = new SoapInvokerHandler();
invokerHandler.initCall();
SoapService service = (SoapService) Proxy.newProxyInstance(SoapService.class.getClassLoader(), new Class[] { SoapService.class },
invokerHandler);
return service;
}
public static void main(String[] args) throws ServiceException {
System.out.println(SoapInvokerFactory.getInvoker().getDatabaseConfiguration());
}
}