Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Wiki Markup
{snippet:id=e3|lang=java|url=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionHandleAndTransformTest.java}

Using

...

useOriginalMessage

Available as of Camel 2.0
The option useOriginalBody useOriginalMessage is used for routing the original input body instead of the current body that potential is modified during routing.

...

The route listen for JMS messages and validates, transforms and handle it. During this the Exchange payload is transformed/modified. So in case something goes wrong and we want to move the message to another JMS destination, then we can add an onException. But when we move the Exchange to this destination we do not know in which state the message is in. Did the error happen in before the transformOrder or after? So to be sure we want to move the original input message we received from jms:queue:order:input. So we can do this by enabling the useOriginalBody useOriginalMessage option as shown below:

Code Block
java
java
    // will use original input body
    onException(MyOrderException.class)
       .useOriginalBodyuseOriginalMessage().handled(true)
       .to("jms:queue:order:failed");

Then the messages routed to the jms:queue:order:failed is the original input. If we want to manually retry we can move the JMS message from the failed to the input queue, with no problem as the message is the same as the original we received.

...

useOriginalMessage with Spring DSL

The useOriginalBody useOriginalMessage option is defined as a boolean attribute on the <onException> XML tag in Spring DSL. So the definition above would be:

Code Block
xml
xml
    <onException useOriginalBodyuseOriginalMessage="true">
        <exception>com.mycompany.MyOrderException</exception>
        <handled><constant>true</constant></handled>
        <to uri="jms:queue:order:failed"/>
    </onException>

...