I have a transacted route and onException clause that tells Camel to use original body on redelivery.
If I modify body somewhere in the route, I am expecting to still receive original body on redelivery. That works fine if I do something like setBody(constant("xyz")), but if I use setBody(bean("somebean")) or to("bean:somebean") the body seems to be lost. Happens both in 2.1-SNAPSHOT and 2.0.0 Here is unit test: ===================== OnExceptionTest-context.xml ====================== <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:amq="http://activemq.apache.org/schema/core" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core-5.3.0.xsd"> <!-- This creates an embedded ActiveMQ Broker --> <broker xmlns="http://activemq.apache.org/schema/core" useJmx="false" persistent="false" id="activeMQBroker"> <transportConnectors> <transportConnector uri="tcp://localhost:61616" /> </transportConnectors> </broker> <!-- setup JMS connection factory --> <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="activeMQBroker"> <property name="brokerURL" value="vm://localhost?create=false"/> </bean> <!-- setup spring jms TX manager --> <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager"> <property name="connectionFactory" ref="jmsConnectionFactory"/> </bean> <bean id="foo" class="org.apache.camel.OnExceptionTest$FooBean"/> <!-- define Camel activemq component --> <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent"> <property name="connectionFactory" ref="jmsConnectionFactory"/> <!-- define the jms consumer/producer as transacted --> <property name="transacted" value="true"/> <!-- setup the transaction manager to use --> <property name="transactionManager" ref="jmsTransactionManager"/> </bean> <bean id="routeBuilder" class="org.apache.camel.OnExceptionTest $TestRoutes"/> <camelContext xmlns="http://camel.apache.org/schema/spring"> <routeBuilder ref="routeBuilder"/> </camelContext> </beans> ===================== OnExceptionTest.java ====================== package org.apache.camel; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.annotation.DirtiesContext; import org.apache.camel.spring.SpringRouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.testng.annotations.Test; /** * @author Dragisa Krsmanovic */ @ContextConfiguration public class OnExceptionTest extends AbstractTestNGSpringContextTests { @EndpointInject(uri = "mock:end") protected MockEndpoint endpoint; @EndpointInject(uri = "mock:error") protected MockEndpoint error; @EndpointInject(uri = "mock:checkpoint") protected MockEndpoint checkpoint; @Produce(uri = "activemq:start") protected ProducerTemplate start; @Produce(uri = "activemq:broken") protected ProducerTemplate broken; @Test @DirtiesContext public void testWithBean() throws InterruptedException { endpoint.expectedMessageCount(0); error.expectedMessageCount(1); checkpoint.expectedMessageCount(3); checkpoint.allMessages().body().isEqualTo("foo"); broken.sendBody("foo"); checkpoint.assertIsSatisfied(); error.assertIsSatisfied(); endpoint.assertIsSatisfied(); } @Test @DirtiesContext public void testWithConstant() throws InterruptedException { endpoint.expectedMessageCount(0); error.expectedMessageCount(1); checkpoint.expectedMessageCount(3); checkpoint.allMessages().body().isEqualTo("foo"); start.sendBody("foo"); checkpoint.assertIsSatisfied(); error.assertIsSatisfied(); endpoint.assertIsSatisfied(); } public static class FooBean { @Handler public String process(@Body String body) { return "oh no"; } } public static class TestRoutes extends SpringRouteBuilder { @Override public void configure() throws Exception { onException(Exception.class) .handled(true) .useOriginalBody() .maximumRedeliveries(2) .to("mock:error"); from("activemq:broken") .transacted() .to("mock:checkpoint") .setBody(bean("foo")) .throwException(new Exception("boo")) .to("mock:end"); from("activemq:start") .transacted() .to("mock:checkpoint") .setBody(constant("")) .throwException(new Exception("boo")) .to("mock:end"); } } } -- Dragisa Krsmanovic Java Developer Public Library of Science http://www.plos.org -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- This email is confidential to the intended recipient. If you have received it in error, please notify the sender and delete it from your system. Any unauthorized use, disclosure or copying is not permitted. The views or opinions presented are solely those of the sender and do not necessarily represent those of Public Library of Science unless otherwise specifically stated. Please note that neither Public Library of Science nor any of its agents accept any responsibility for any viruses that may be contained in this e-mail or its attachments and it is your responsibility to scan the e-mail and attachments (if any).