I guess the xml snippet got lost in the markup.... I've simplified the flows somewhat but everything should be in there....
The main questions are : * why is the complex-route's onException triggered when an exchange never went into the complex-route but stayed in the main-route * logging : why it uses complex-route and not main-route in the logging for the "Using real dispatcher" log statement. (again for exchanges that never went into the complex-route. I've put the 2 snippets in the following Gist as well : https://gist.github.com/ddewaele/5097516 The "design" was based on the How do I import routes from other XML files <http://camel.apache.org/how-do-i-import-routes-from-other-xml-files.html> article, but there we have 2 independent routes, where here we have nested routes. main-flow : <beans xmlns="http://www.springframework.org/schema/beans"> <import resource="camel-complex-route.xml"/> <camel:camelContext xmlns="http://camel.apache.org/schema/spring" id="camelContext" useMDCLogging="true"> <camel:routeContextRef ref="complex-route-context"/> <-- Here we also noticed that in the logging the "Using real dispatcher" log statement was logged like this : 2013-03-06 09:00:29.665 [Camel (camelContext) thread #8 - vm://input] complex-route - Using real dispatcher Notice how it uses complex-route and not main-route --> <camel:interceptSendToEndpoint uri="http4://endpoint?throwExceptionOnFailure=false" skipSendToOriginalEndpoint="true"> <choice> <when> <simple>${header.header1}</simple> <log message="Faking dispatcher"/> <bean ref="fakeDispatcher" method="dispatch" /> </when> <when> <simple>${header.header2}</simple> <log message="Overriding dispatcher"/> <setHeader headerName="CamelHttpUri"> <simple>http://localhost:8085/overridden-service/${service_name}</simple> </setHeader> <to uri="http4://endpoint?throwExceptionOnFailure=false" /> </when> <otherwise> <log message="Using real dispatcher"/> <to uri="http4://endpoint?throwExceptionOnFailure=false" /> </otherwise> </choice> </camel:interceptSendToEndpoint> <camel:route id="main-route" streamCache="true"> <camel:from id="camelservlet" uri="servlet:///someUrl?httpBindingRef=mfBinding&matchOnUriPrefix=true" /> <-- entry point for the main flow --> <camel:from uri="vm:input" /> <camel:onException> <camel:exception>java.lang.Exception</camel:exception> <camel:handled> <constant>true</constant> </camel:handled> <camel:process ref="exceptionProcessor" /> <camel:process ref="process4" /> <camel:process ref="process5" /> </camel:onException> <camel:process ref="process1" /> <camel:process ref="process2" /> <camel:process ref="process3" /> <-- Dispatch Message. Here we decide to use complex processing ( = entering the complex route) to use simple processing ( = simple dispatching and never entering the complex route) We noticed that when an exception occured during simple processing (and the complex route was never entered), the onException from the complex route was triggered, instead of the onException from the mainFlow. --> <choice> <when> <simple>${header.complexProcessingRequired}"</simple> <log message="Using complex processing"/> <to uri="direct:complex-route-in"/> </when> <otherwise> <log message="Using simple processing"/> <to uri="http4://endpoint?throwExceptionOnFailure=false" /> </otherwise> </choice> <camel:process ref="process4" /> <camel:process ref="process5" /> </camel:route> </camel:camelContext> </beans> complex-flow <beans > <camel:routeContext id="complex-route-context"> <camel:route id="complex-route" streamCache="true"> <-- our main flow uses this from endpoint to enter this route --> <camel:from uri="direct:complex-route-in" /> <-- when an exchange in our main route never entered this route, this onException is still getting called. --> <camel:onException> <camel:exception>java.lang.Exception</camel:exception> <camel:handled> <camel:constant>true</camel:constant> </camel:handled> <camel:process ref="exceptionProcessor" /> <camel:process ref="complexprocess4" /> <camel:process ref="complexprocess5" /> </camel:onException> <camel:process ref="complexprocess1" /> <camel:process ref="complexprocess2" /> <camel:process ref="complexprocess3" /> </camel:route> </camel:routeContext> </beans> -- View this message in context: http://camel.465427.n5.nabble.com/Camel-multiple-nested-routes-in-one-context-tp5728576p5728643.html Sent from the Camel - Users mailing list archive at Nabble.com.