...
Now suppose the route above and a failure happens in the foo
bean. Then the Exchange.TO_ENDPOINT
and Exchange.FAILURE_ENDPOINT
will still contain the value of http://someserver/somepath
.
OnPrepareFailure
Available as of Camel 2.16
Before the exchange is sent to the dead letter queue, you can use onPrepare to allow a custom Processor
to prepare the exchange, such as adding information why the Exchange failed. For example the following processor adds a header with the exception message
Code Block |
---|
public static class MyPrepareProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
exchange.getIn().setHeader("FailedBecause", cause.getMessage());
}
} |
Then configure the error handler to use the processor as follows:
Code Block |
---|
errorHandler(deadLetterChannel("jms:dead").onPrepareFailure(new MyPrepareProcessor())); |
Configuring this from XML DSL is as shown:
Code Block |
---|
<bean id="myPrepare"
class="org.apache.camel.processor.DeadLetterChannelOnPrepareTest.MyPrepareProcessor"/>
<errorHandler id="dlc" type="DeadLetterChannel" deadLetterUri="jms:dead" onPrepareFailureRef="myPrepare"/> |
The onPrepare is also available using the default error handler.
Which route failed
Available as of Camel 2.10.4/2.11
...