我正在使用 Apache Camel 访问 Web 服务。 我正在尝试将内容注入(inject)我从 WebService 接收的数据以进行测试。 使用 getBody(),我只能访问从接收到的 XML 反序列化的 Java 对象。有谁知道我如何访问原始 XML - 在 Camel 反序列化之前?
这是我的路线结构。如您所见,我创建了一个从 bean eaigateway 到我正在查询的真实 WebService(bean webservice)的代理 Webservice。
from("cxf:bean:eaigateway")
.routeId(ROUTE_ID_GATEWAY)
.process(new EnrichBean())
.to(ENDPOINT_WEBSERVICE)
.process(new DisenrichBean())
;
from(ENDPOINT_WEBSERVICE)
.routeId(ROUTE_ID_WEBSERVICE)
.to("cxf:bean:webservice")
;
public class DisenrichBean implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
// This contains the unserialized object returned from the webservice.
// But how to get and set the original XML content?
Object antwort = ((MessageContentsList)(exchange.getIn().getBody())).get(0);
}
}
最佳答案
原始消息应可从以下位置获得:
exchange.getUnitOfWork().getOriginalInMessage()
但在您的情况下,您似乎需要对象/XML 编码。 一些例子可以在这里找到:http://camel.apache.org/data-format.html
关于java - Apache Camel : Access original data (XML) returned from WebService,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49652319/