Skip to content

Instantly share code, notes, and snippets.

@ddewaele
Last active December 14, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddewaele/5097516 to your computer and use it in GitHub Desktop.
Save ddewaele/5097516 to your computer and use it in GitHub Desktop.
<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>
<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&amp;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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment