Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache camel 如何使用ApacheCamel交换消息?_Apache Camel - Fatal编程技术网

Apache camel 如何使用ApacheCamel交换消息?

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

我是阿帕奇骆驼队的新人。请看一下我下面的代码:

我有一个公开为cxf webservice的服务:

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%确定 这个
  • 改变

    .setHeader()是指使用简单语言时。在99%的情况下,getIn()就足够了

    exchange.getOut().setHeader("header.temporary", new OutputType());
    
    exchange.getIn().setHeader("temporary"), new OutputType());