JaxWsProxyFactoryBean是客户端调用
JaxWsServerFactoryBean是服务端发布
项目中使用客户端调用的代码如下:
public T buildService(String address,Long timeout) throws Exception {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(clazz);
factory.setAddress(address);
T service = (T) factory.create();
configPolicy(service,timeout);
return service;
}
/**
* 设置服务的客户端策略
* 连接时间: 默认=30s 设置为15s,
* 接收超时时间: 默认=60s 设置为15s
* 自动分组:默认=true 设置为false
* 是否保持连接:使用默认设置=true
* @param service 服务实例
*/
private void configPolicy(T service,Long timeout) {
Client clientP = ClientProxy.getClient(service);
HTTPConduit http = (HTTPConduit) clientP.getConduit();
HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
if(timeout != null) {
httpClientPolicy.setConnectionTimeout(timeout);
httpClientPolicy.setReceiveTimeout(timeout);
}else{
httpClientPolicy.setConnectionTimeout(this.timeout);
httpClientPolicy.setReceiveTimeout(this.timeout);
}
httpClientPolicy.setAllowChunking(false);
http.setClient(httpClientPolicy);
}
网上发布服务的例子:
HelloWorldImpl implementor = new HelloWorldImpl();
JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean();
svrFactory.setServiceClass(HelloWorld.class);
svrFactory.setAddress("http://localhost:9000/helloWorld");
svrFactory.setServiceBean(implementor);
svrFactory.create();
标签:cxf,service,JaxWsServerFactoryBean,svrFactory,JaxWsProxyFactoryBean,timeout,http From: https://blog.51cto.com/u_16071779/6190737