I have a route that defines a doTry-doCatch block. When the exception is handled in the doCatch block I want it to be propagated to the error handler to make sure the message is added to the dead letter queue after handling it locally. Problem is that I can't get the propagation to the error handler to work ("defaultErrorHandler called!" is not printed to the console). I also tried with onException, but also no luck.
Any hints greatly appreciated. Regards, Oliver
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
errorHandler(deadLetterChannel("ref:myDLQ")
.log("defaultErrorHandler called! ${body}"));
final RouteDefinition route = from("seda:queue.inbox");
route
.doTry()
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("throwing ex");
throw new IllegalArgumentException("test");
}
})
.doCatch(Exception.class)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("handling ex");
route.log(LoggingLevel.ERROR, "Exception in route: ${body}");
throw new IllegalArgumentException("rethrow");
}
})
.log("Received order ${body}")
.to("mock:queue.order");
}
};
}