Hello,We have a system where we want to monitor all the exchanges flowing throw camel pipeline (track completed, inprogress, failed exchanges).
*Camel context are added at runtime*. We want enrich pipeline to trigger start and end of work flow, also add error handler to pipeline. Start interceptor marks exchange as inprogress, end interceptor marks exchange as completed and error handler marks exchange as failed in the database.
We are loading camel context from spring xml, then in java using RouteDefination's adviceWith method modifying route to add start, end intercepters and error handler.
Camel context spring xml: <camel:camelContext id="default" autoStartup="true"> <camel:route id="startRoute"> <camel:from uri="direct:input" /> <camel:process ref="processor1" /> <camel:to uri="direct://interm" /> </camel:route> .... </camel:camelContext> Adding error handler using /route.adviceWith(camelContext, new RouteBuilder() { public void configure() throws Exception {onException(Exception.class).handled(true).process(ERROR_HANDLER);
} }); /Adding start intercepter using /routeDef.adviceWith(camelContext, new RouteBuilder() { public void configure() throws Exception { interceptFrom().process(START_INTERCEPTER); } }); /Adding end intercepter using /routeDef.adviceWith(camelContext, new RouteBuilder() { public void configure() throws Exception { onCompletion().process(END_INTERCEPTER); } }); / Now when we try to send exchange on input channel using /Exchange exchange1 = new DefaultExchange(context); exchange1.getIn().setBody("Input1"); context.createProducerTemplate().send("direct://input", exchange1); / it throws NPE and* *our error handler is called. java.lang.NullPointerExceptionat org.apache.camel.model.InterceptFromDefinition$1.evaluate(InterceptFromDefinition.java:77) at org.apache.camel.builder.ProcessorBuilder$4.process(ProcessorBuilder.java:94) at org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsyncProcessorBridge.process(AsyncProcessorTypeConverter.java:50) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:70)
When we try to send exchange using / Exchange exchange2 = new DefaultExchange(context); exchange2.getIn().setBody("Input2"); Endpoint endpoint = context.getEndpoint("direct://input"); exchange2.setFromEndpoint(endpoint); context.createProducerTemplate().send(endpoint, exchange2);/it pass all the way to pipeline very well. *But in case of exception in pipeline default error handler gets called and not the error handler that we added*.
Are we doing in a wrong way or there is any problem with camel when modifying routes at runtime.
Any help appreciated in advance. P.S.: maven project attached. Regards, Sumit Teke.
camel-sample.tar.gz
Description: GNU Zip compressed data