Exchange.getIn()。getBody()返回在第二个电话骆驼空字符串 [英] Exchange.getIn().getBody() returns empty string in camel on second call
问题描述
我有2个相同的呼叫:
String msg1 = exchange.getIn().getBody(String.class);
String msg2 = exchange.getIn().getBody(String.class);
在MSG1我得到正确的预期值,但MSG 2是一个空字符串。我不是设置在走出消息,左右交换在信息应该是仍然完好无损。请解释为什么会这样。
In msg1 I get the correct expected value , but msg2 is an empty string. I'm not setting the Out message , so the exchange In message should be still intact. Please explain why this is happening.
骆驼路线:
<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的处理是正确的,但在路径2我得到的描述的行为:第一个电话 - 有效的字符串,第二个电话 - 空字符串。所以我想,也许它是与HttpMessage转换。
The processor contains only the 2 statements from above. The processing in route1 is correct , but in route2 I get the described behaviour : first call - valid string , second call - empty string. So I think maybe it has something to do with HttpMessage conversion.
推荐答案
http://camel.apache.org/jetty。 HTML
Jetty是基于流的,这意味着它接收输入提交
骆驼作为流。这意味着你将只能阅读
流一次的内容。
Jetty is stream based, which means the input it receives is submitted to Camel as a stream. That means you will only be able to read the content of the stream once.
只需将输入字符串中的前使用两次或更多次
Just convert the input in a String before use it twice or more times
<route id="route2">
<from uri="jetty://http://localhost:8090" />
<convertBodyTo type="String" />
<process ref="messageProcessor" />
</route>
这篇关于Exchange.getIn()。getBody()返回在第二个电话骆驼空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!