gpt4 book ai didi

java - apache Camel Web 服务客户端

转载 作者:行者123 更新时间:2023-12-01 11:40:07 25 4
gpt4 key购买 nike

我已经在我的 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

来调用此 Web 服务
@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,因此我可以看到请求正在发送,因为它正在被接收,但我不知道如何处理响应。

line System.out.println(exchange_.getOut().getBody()); 在发送 WebService 时返回 null收到响应。

谁能告诉我如何处理来自 Exchange 的响应?

最佳答案

回复来自 pt.send 返回的内容。

process方法仅用于配置请求方法。不是为了得到回复。回复来自 pt.send 返回的内容。

Exchange reply = pt.send(...)

另请注意 OUT 与 IN 请参阅此常见问题解答 http://camel.apache.org/using-getin-or-getout-methods-on-exchange.html

关于java - apache Camel Web 服务客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29599560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com