67.5. 例子
67.5.1. Web 服务客户端 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
以下路由支持 marshalling 请求并取消处理响应或错误。
String WS_URI = "cxf://http://myserver/customerservice?serviceClass=com.example.customerservice&dataFormat=RAW";
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
from("direct:customerServiceClient")
.onException(Exception.class)
.handled(true)
.unmarshal(soapDF)
.end()
.marshal(soapDF)
.to(WS_URI)
.unmarshal(soapDF);
以下片段为服务接口创建一个代理,并对上述路由发出 SOAP 调用。
import org.apache.camel.Endpoint;
import org.apache.camel.component.bean.ProxyHelper;
...
Endpoint startEndpoint = context.getEndpoint("direct:customerServiceClient");
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
// CustomerService below is the service endpoint interface, *not* the javax.xml.ws.Service subclass
CustomerService proxy = ProxyHelper.createProxy(startEndpoint, classLoader, CustomerService.class);
GetCustomersByNameResponse response = proxy.getCustomersByName(new GetCustomersByName());
67.5.2. Web 服务服务器 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
使用以下路由设置 web 服务服务器,它侦听 jms 队列 customerServiceQueue,并使用类 CustomerServiceImpl 处理请求。课程的 customerServiceImpl 应该实施接口 CustomerService。而不必直接实例化服务器类,而是作为常规 bean 在 spring 上下文中定义。
SoapJaxbDataFormat soapDF = new SoapJaxbDataFormat("com.example.customerservice", new ServiceInterfaceStrategy(CustomerService.class));
CustomerService serverBean = new CustomerServiceImpl();
from("jms://queue:customerServiceQueue")
.onException(Exception.class)
.handled(true)
.marshal(soapDF)
.end()
.unmarshal(soapDF)
.bean(serverBean)
.marshal(soapDF);