Custom Route Builders / Interceptors / Exception Handlers

With the custom route builders it is possible to:

  • extend the base application functionality by adding additional route builders to the existing camel context
  • extend the existing route builder functionality by injecting additional interceptors to this route builder
  • extend the existing route builder exception handling by injecting additional exception handlers to this route builder

The abstract class org.openehealth.ipf.platform.camel.core.config.CustomRouteBuilder must be extended by all your custom route builders (also the ones in the base application). If the intercepted property is set, it is assumed that the custom route builder is an interceptor or an exception handler and the CustomRouteBuilderConfigurer will try to inject it to the referenced intercepted route builder.

Otherwise if the intercepted property is not set, the CustomRouteBuilderConfigurer will inject this custom route builder to the existing camel context.

The CustomRouteBuilder beans will be recognized by the CustomRouteBuilderConfigurer and added in desired order to the camel context respectively.


Here is a fragment of a base custom route builder class:

    class BaseRoute extends CustomRouteBuilder {
        void configure() {

And the corresponding Spring application context shown below. Note that the custom route builder must not be explicitly associated to the Camel context.

  <camel:camelContext id="camelContext" />

  <!-- Required to pick up the BaseRoute and add it to the Camel Context -->

  <!-- Picking up custom route builders -->
  <bean id="customRouteBuilderConfigurer"
    <property name="camelContext" ref="camelContext" />

  <bean id="postProcessor"
      <property name="springConfigurers" >
          <ref bean="customRouteBuilderConfigurer" />
          <!-- potentially more configurers -->

  <!-- Usually this is defined in a different Spring context file -->
  <bean id="baseRoute" class="org.openehealth.ipf.tutorial.config.route.BaseRoute" />

A custom interceptor is defined in separate CustomRouteBuilder and extends the functionality of the BaseRoute by intercepting the inputs from the 'seda:input' endpoint:

    class CustomInterceptingRoute extends CustomRouteBuilder{
        void configure() {

               // do some more stuff to handle this exception


The Spring beans definition is shown below, this time as Groovy script that is compiled as load time. Note the intercepted property is set to the custom route builder to be intercept. If started in same application context, this interceptor will intercept all incoming exchanges to the "seda:input" endpoint in the base route and translate it with the logic implemented in customTransmogrifier bean (not shown in this sample). Also, the custom exception handler is added to the intercepted route.

    <beans xmlns=""

      <lang:groovy id="interceptorRoute"
          script-source="classpath:config/CustomInterceptingRoute.groovy" >
          <lang:property name="intercepted" ref="baseRoute" />

      <lang:groovy id="customTransmogrifier"
          script-source="classpath:config/CustomTransmogrifier.groovy" />