我在camel-context.xml
内创建了端点和路由,如下所示:
<cxf:cxfEndpoint id="testEndpoint" address="https://127.0.0.1:443/ws"
serviceClass="pl.test.ws.testWsImpl"
wsdlURL="/META-INF/wsdl/testCFService.wsdl"
endpointName="s:test_Port"
serviceName="s:testDescriptor"
xmlns:s = "test.namespace"/>
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct://start" />
<to uri="cxf:bean:testEndpoint" />
</route>
</camelContext>
然后我尝试通过创建ProducerTemplate
来调用此网络服务
@Produce(uri="direct:start")
ProducerTemplate pt;
并向其中发送消息:
pt.send(new Processor() {
public void process(Exchange exchange_) throws Exception {
TestRequest test = new TestRequest();
test.setRequest("hello world");
exchange_.getIn().setBody(test);
System.out.println(exchange_.getOut().getBody());
}});
我已经在本地启动并运行了WebService
,因此我可以看到请求正在发送,因为它正在接收,但是我不知道如何处理响应。
第 System.out.println(exchange_.getOut().getBody());
行在发送null
响应时返回WebService
Received
值。
谁能告诉我如何处理Exchange
的回复?
回复来自 pt.send 返回的内容。
进程方法仅用于配置请求方法。没有得到答复。回复来自pt.send
返回的内容。
Exchange reply = pt.send(...)
还要注意 OUT vs IN 请参阅此常见问题解答http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html