Documentation and samples says, that ProducerTemplate.sendBody should send
any Object.
However in my setup, it seems to call toString on the object, so it's not
the real object that is sent - unless the object is a String.
Here is my test, which prints: *************process body: :
ProducerTemplateTest$A@b8deef - because my object does not have overrided
toString. If I override toString (uncommenting it) it will print 'hello' all
right.
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class ProducerTemplateTest extends CamelTestSupport {
@Test
public void firstTest() throws Exception {
ProducerTemplate producer = context.createProducerTemplate();
producer.sendBody("direct:start", new A());
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start")
.process(new Processor() {
public void process(Exchange exchange)
throws Exception {
String body =
exchange.getIn().getBody(String.class);
System.out.println("*************process body:
: " +
body);
exchange.getIn().setBody(body);
}
})
.to("mock:result");
}
};
}
class A {
String s = "hello";
// public String toString(){
// return s;
// }
}
}
Best Regards
Hardy Henneberg
--
View this message in context:
http://camel.465427.n5.nabble.com/ProducerTemplate-sendBody-calls-toString-tp5722350.html
Sent from the Camel - Users mailing list archive at Nabble.com.