Mule ESB interceptors are useful for attaching behaviors to multiple service components. The interceptor pattern is often referred to as practical AOP (Aspect Oriented Programming), as it allows the developer to intercept processing on an object and potentially alter the processing and outcome. (See also Spring AOP). Interceptors are very useful for attaching behavior such as profiling and permission and security checks to your service components.
AbstractEnvelopeInterceptor is an envelope filter that will execute before and after the component is invoked. Good for logging and profiling.
If you want to intercept a message flow to a component on the inbound message flow, you should implement the Interceptor interface. It has a single method:
1 MuleMessage intercept(Invocation invocation) throws MuleException;
invocation parameter contains the current message and the
Service object of the target component. Developers can extract the current
MuleMessage from the message and manipulate it as needed. The
intercept method must return a
MuleMessage that is passed on to the component (or to the next interceptor in the chain).
The AbstractEnvelopeInterceptor is an envelope filter that executes before and after the component is invoked. Good for logging and profiling. works in the same way, except that it exposes two methods that get invoked before and after the event processing:
1 2 3 MuleMessage before(Invocation invocation) throws MuleException; MuleMessage after(Invocation invocation) throws MuleException;
Interceptors can be configured on your components as follows:
1 2 3 4 5 6 7 8 9 <service name="MyService"> <component> <custom-interceptor class="org.my.CustomInterceptor"/> <logging-interceptor/> <interceptor-stack ref="testInterceptorStack"/> <timer-interceptor/> <prototype-object class="org.my.ComponentImpl"/> </component> </service>
| When you configure interceptors, you must specify the object factory explicitly (in this example,
You can also define interceptor stacks, which are one or more interceptors that can be referenced using a logical name. To use an interceptor stack, you must first configure it in the global section of the Mule XML configuration file (above the
1 2 3 4 <interceptor-stack name="default"> <custom-interceptor class="org.my.CustomInterceptor"/> <logging-interceptor/> </interceptor-stack>
You can configure multiple
<interceptor> elements on your components, and you can mix using built-in interceptors, custom interceptors, and references to interceptor stacks.
A user-implemented interceptor.
An implementation of the Interceptor interface.