Exchange.getIn()。getBody()在第二次调用时返回骆驼中的空字符串

【字号: 日期:2024-02-26浏览:77作者:雯心
如何解决Exchange.getIn()。getBody()在第二次调用时返回骆驼中的空字符串?

来自http://camel.apache.org/jetty.html

码头是基于流的,这意味着它收到的输入将作为流提交给Camel。这意味着您将只能读取一次流的内容。

只需将输入转换为字符串,然后再使用两次或多次

<route id='route2'> <from uri='jetty://http://localhost:8090' /> <convertBodyTo type='String' /> <process ref='messageProcessor' /></route>解决方法

我有两个相同的电话:

String msg1 = exchange.getIn().getBody(String.class);String msg2 = exchange.getIn().getBody(String.class);

在msg1中,我得到了正确的期望值,但是msg2是一个空字符串。我没有设置 Out 消息,因此exchange In消息应该仍然完整。请解释为什么会这样。

骆驼路线:

<camelContext xmlns='http://camel.apache.org/schema/spring'> <route id='route1'><from uri='timer://myTimer?period=2000' /><setBody> <simple>Hello World ${header.firedTime}</simple></setBody><process ref='messageProcessor' /><to uri='http://localhost:8090'/> </route> <route id='route2'><from uri='jetty://http://localhost:8090' /><process ref='messageProcessor' /> </route></camelContext>

处理器仅包含上面的2条语句。route1中的处理是正确的,但是在route2中,我得到了描述的行为:第一个调用-有效字符串,第二个调用-空字符串。所以我认为也许与HttpMessage转换有关。

相关文章: