Apache camel 如何使用ApacheCamel交换消息?
我是阿帕奇骆驼队的新人。请看一下我下面的代码: 我有一个公开为cxf webservice的服务:Apache camel 如何使用ApacheCamel交换消息?,apache-camel,Apache Camel,我是阿帕奇骆驼队的新人。请看一下我下面的代码: 我有一个公开为cxf webservice的服务: interface CxfService{ public OutputType hello(InputType input); } 这是我的路线: from("cxf:/test?serviceClass=" + CxfService.class.getName()) .to("log:cxfLog1") .recipientList(simple("direct:${h
interface CxfService{
public OutputType hello(InputType input);
}
这是我的路线:
from("cxf:/test?serviceClass=" + CxfService.class.getName())
.to("log:cxfLog1")
.recipientList(simple("direct:${header.operationName}"));
from("direct:hello")
.process(new Processor(){
public void process(Exchange exchange) throws Exception {
InputType file = exchange.getIn().getBody(InputType.class);
exchange.getOut().setBody(new OutputType());
}
});
代码按预期工作,它使用InputType并生成OutputType
我想借我的身体做其他事情,所以我重写如下:
from("cxf:/test?serviceClass=" + CxfService.class.getName())
.to("log:cxfLog1")
.recipientList(simple("direct:${header.operationName}"));
from("direct:hello")
.process(new Processor(){
public void process(Exchange exchange) throws Exception {
InputType file = exchange.getIn().getBody(InputType.class);
exchange.getOut().setHeader("header.temporary", new OutputType());
}
})
.to("some endpoint")
.setBody(simple("${header.temporary}"));
此Web服务使用InputType,但不生成任何内容。有什么问题吗?在第二段代码中,当设置header.temporary时,您应该更改两件事:
setHeader(“临时”,new OutputType())
-不使用“header”前缀
需要-您通过方法调用直接寻址头getIn()
而不是getOut()
。输入将被复制到
输出。你可能想研究一下这个过程
Camel构建消息以获取详细信息-我不能100%确定
这个exchange.getOut().setHeader("header.temporary", new OutputType());
exchange.getIn().setHeader("temporary"), new OutputType());