在项目中看到,不知道干啥用,好像是2.7版本的新方法的在网上搜没有找到相关信息,查看了cxf api 才明白
api url http://cxf.apache.org/javadoc/latest/
备注 :Bean to help easily create Client endpoints for JAX-WS. 大概意思帮助bean简单的创建客户端连接点JAX- WS.
何为JAX-WS. 大概意思是一个远程调用可以转换为一个基于XML的协议,java也就是我们soap协议
方法介绍
setWsdlURL:来自于cxf JaxWsClientFactoryBean父类的父类AbstractWSDLBasedEndpointFactory
字面意思用于获取wsdlUrl也就是soap协议
public void setWsdlURL(String wsdlURL) {//用嵌套类方法给ReflectionServiceFactoryBean封装类传值
getServiceFactory().setWsdlURL(wsdlURL);
}
setAddress:
public void setAddress(String address) {
this.address = address;
}
setServiceClass:传入了生成客户端代码中的映射字段的接口。
public void setServiceClass(Class<?> serviceClass) {
super.setServiceClass(serviceClass);
(super代码 this.serviceClass = serviceClass; )
if (((JaxWsServiceFactoryBean)getServiceFactory()).getJaxWsImplementorInfo() == null) {
//判断传入的wsdlURl是否为空 如果为空的情况下要根据serviceClass给wsdlurl赋值
JaxWsImplementorInfo implInfo = new JaxWsImplementorInfo(serviceClass);
((JaxWsServiceFactoryBean)getServiceFactory()).setJaxWsImplementorInfo(implInfo);
}
}
setBus :传入的是一个bus类型数据,
例如:
SpringBusFactory bf = new SpringBusFactory();
bus = bf.createBus();
SpringBusFactory.setDefaultBus(bus);
SpringBusFactory.setThreadDefaultBus(bus);
jwpf.setBus(bus);
public void setBus(Bus bus) {
this.bus = bus;
}
create :根据名字理解创建客户端
public Client create() {
getServiceFactory().reset(); //设定了 dataBinding=null dataBindingSet为false
if (getServiceFactory().getProperties() == null) {
getServiceFactory().setProperties(properties);
} else if (properties != null) {
getServiceFactory().getProperties().putAll(properties);
}
Client client = null;
Endpoint ep = null;
try {
ep = createEndpoint();
this.getServiceFactory().sendEvent(FactoryBeanListener.Event.PRE_CLIENT_CREATE, ep);
applyProperties(ep);
client = createClient(ep);
initializeAnnotationInterceptors(ep, getServiceClass());
} catch (EndpointException e) {
throw new ServiceConstructionException(e);
} catch (BusException e) {
throw new ServiceConstructionException(e);
}
applyFeatures(client);
this.getServiceFactory().sendEvent(FactoryBeanListener.Event.CLIENT_CREATED, client, ep);
return client;
}
获取了client 还该怎么做呢如下
client.setThreadLocalRequestContext(true);下面是注解的翻译
设置请求上下文是线程本地的还是全局的。默认情况下,请求上下文是“全局”的,在上下文中设置的任何值都可以通过使用此客户端的所有线程看到。如果设置为true,背景改为一个ThreadLocal和设置的值不被其他线程看到。