Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

InterceptStrategy

0..n

To use your own Interceptor Intercept that intercepts every processing steps in all routes in the CamelContext. For instance you can use this to do an AOP like performance timer interceptor.

...

Imagine that you have multiple CamelContext and you want to configure that they all use the same container wide interceptor. How do we do that? Well we can leverage the fact that Camel can auto detect and use custom interceptors. So what we simply do is to define our interceptor in the spring xml file. The sample below does this and also define 2 camel contexts. The sample is based on unit test.TODO: snippet XML e1

Wiki Markup
{snippet:id=e1|lang=xml|title=Spring DSL|url=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/interceptor/ContainerWideInterceptorTest.xml}

Okay lets build our interceptor to simply count the number of interceptions. This is quite easy as we can just implement this logic in our implementation directly as the code below illustrates:TODO: snippet java e1

Wiki Markup
{snippet:id=e1|lang=java|title=InterceptorStrategy|url=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptorTest.java}

See Also