I'm trying to configure an exception handler for all exceptions thrown by all routes in my camel context. My approach is the following, with no luck:
- Instantiate a default camel context
- Retrieve a list of RouteDefinition from a spring context
- Add these definitions to the camel context by calling ctx.addRouteDefinitions()
- Add my exception handler route from a java dsl defined RotueBuilder (ctx.addRoutes(new MyErrorHandlerRouteBuilder())
- Start the camel context
At this point, exceptions thrown inside the routes defined in spring are handled by the DefaultErrorHandler, not the one I'm trying to define. Here's what my error handling route definition looks like
public class MyErrorHandlerRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
onException(Exception.class)
.routeId("errorHandlerRoute")
.handled(true)
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Throwable caused = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
// do some custom processing of the exception
}
})
.stop();
}
What else can I try, or where am I going wrong?