LibraryLink ToToggle FramesPrintFeedback

Implementing a Delegate Processor

If you need to write code that executes both before and after an exchange is delegated to the next processor, you can implement a delegate processor, as explained in this section. Delegate processors conform to the chaining model for building routes.

Example 2.3 shows a partial outline of the org.apache.camel.processor.DelegateProcessor class. The main difference between the DelegateProcessor class and the Processor class is that the DelegateProcessor class has a bean property, processor, which holds a reference to the next processor in the chain. This makes it possible for you to call the next processor explicitly when you write the code for the process() method. The most convenient way to call the next processor in the chain is to call the processNext() method.


Where the setProcessor() method enables the route builder to inject a reference to the next processor in the chain and the process() method must be overridden by your custom delegate processor class.

You implement a delegate processor by extending DelegateProcessor and implementing the process() method. Example 2.4 shows the outline of a delegate processor implementation.


Where the process() method contains code that gets executed before delegating to the next processor in the chain, as well as code that gets executed after delegating. If the processors in your route are chained according to the chaining model (see Chaining model), this means that you can access request messages before the call to processNext() and access reply messages after the call.

For examples of how to access the message body and header values inside a simple processor, see Accessing Message Content.

To insert a delegate processor into a route, use the intercept() DSL command. Create an instance of your custom processor and then pass this instance as an argument to the intercept() method, as follows:

// Java
org.apache.camel.processor.DelegateProcessor myProc = new MyDelegateProcessor();

from("SourceURL").intercept(myProc).to("TargetURL");