【发布时间】:2018-08-07 01:12:33
【问题描述】:
在我的项目中,我必须创建一些 Soap Web 服务客户端我正在使用 apache cxf 创建端口并使用 Web 服务我注意到端口创建我复制了很多代码,所以我创建了一个抽象类像这样
public abstract class WebServiceConsumerPort<P>{
protected Class<P> port;
private static Logger log = LoggerFactory.getLogger(WebServiceConsumerPort.class);
public void createPort(String url, String timeoutS) {
try {
Long timeout = Long.parseLong(timeoutS);
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(port.getClass());
factory.setAddress(url);
port = (Class<P>) factory.create();
Client client = ClientProxy.getClient(port);
if (client != null) {
log.info("Timeout WEB WERVICES: {}", timeout);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setAllowChunking(false);
policy.setConnectionTimeout(timeout * 1000);
policy.setReceiveTimeout(timeout * 1000);
conduit.setClient(policy);
}
} catch (Exception e) {
log.error("Peoblem creating the port", e);
}
}
}
然后我想创建特定的类来创建端口: 例如,我有带有方法 method1() 和 method2() 的 WebService1 和带有方法 method3() 和 method4() 的 WebService2
我的消费者看起来像:
public class WebService1Consumer extends WebServiceConsumerPort<WebService1Interface> {
public void consumeMethod1() {
port.method1();
}
public void consumeMethod2() {
port.method2();
}
}
另一个类看起来像
public class WebService2Consumer extends WebServiceConsumerPort<WebService2Interface> {
public void consumeMethod1() {
port.method3();
}
public void consumeMethod2() {
port.method4();
}
}
但是在两个类中说不能解析端口中的方法。
【问题讨论】:
标签: java generics cxf hierarchy