You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Intercept

The intercept feature in Camel supports intercepting Exchanges while they are on route.

Camel supports two kinds of interceptors

  • intercept
  • interceptEndpoint new in Camel 2.0 that intercepts when an Exchange is about to be sent to the given Endpoint

Intercept

Lets start with the logging example. We want to log all the incoming requests so we use intercept to route to the Log component. As proceed is default then the Exchange will continue its route, and thus it will continue to mock:first.

Error formatting macro: snippet: java.lang.NullPointerException

InterceptEndpoint

Available as of Camel 2.0

Intercept endpoint is triggered when an Exchange is being sent to the intercepted endpoint. This allows you to route the Exchange to a Detour or do some custom processing before the Exchange is sent to the original intended destination. You can also skip sending to the intended destination. By default Camel will send to the original intended destination after the intercepted route completes. And as the regular intercept you can also define an when Predicate so we only intercept if the Predicate evaluates to true. This allows you do do a bit of filtering, to only intercept when certain criteria is meet.

Let start with a simple example, where we want to intercept when an Exchange is being sent to mock:foo:

Error formatting macro: snippet: java.lang.NullPointerException

And this time we add the Predicate so its only when the message body is Hello World we intercept.

Error formatting macro: snippet: java.lang.NullPointerException

And to skip sending to the mock:foo endpoint we use the stop() DSL in the route at the end to instruct Camel to skip sending. The name *stop() is used as the interceptEndpoint builds on top of intercept and thus we inherit the DSL keywords.

Error formatting macro: snippet: java.lang.NullPointerException
  • No labels