I have 2 identical calls:
String msg1 = exchange.getIn().getBody(String.class);
String msg2 = exchange.getIn().getBody(String.class);
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.
Camel routes:
<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>
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.
From http://camel.apache.org/jetty.html
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With