Message Interceptors
requires version 1.3.0 or above
The architecture of the Membrane monitor and router is open for extension. To add functionality or to change the behavior, an interceptor can be plugged into the flow of messages. When a message flows through the router, the interceptors are called. An interceptor can:
- Read the content of a message and the protocol information like HTTP header fields.
- Modify the content of a message or its protocol information. It can for instance change the destination of a message.
- Stop the message processing and return a message.

Figure 1:
After the router has done it’s processing, the request is sent to the server. Then the server does its work and returns a response to the router. The router then invokes the interceptor again and passes the exchange reference to the handleResponse method. The exchange object is the same as the one passed to handle Request. But this time it contains a request and a response message.
Lifecycle
An interceptor is a singleton and therefore has only one instance. The instance is configured by a Spring configuration or by an API. If you need a per exchange lifecycle you can simulate this by using a Map like the following in your interceptor:
Map<Exchange, Object> session = new HashMap<Exchange, Object>();
Interceptor Interface
Listening 1 shows the interceptor interface.
public interface Interceptor extends XMLElement {
public Outcome handleRequest(Exchange exc) throws Exception;
public Outcome handleResponse(Exchange exc) throws Exception;
public String getDisplayName();
public void setDisplayName(String name);
public String getId();
public void setId(String id);
}
Configuration
Interceptors are configuerd in the monitor-beans.xml or router-beans.xml file. You will find there some examples and comments about the configuration.
Included Interceptors
Membrane comes with a couple of interceptors.
Core functionality
Some interceptors are used by the router and monitor to provide core functionality.
- RuleMatchingInterceptor
- ExchangeStoreInterceptor
- WSDLInterceptor
- DispatchingInterceptor
Additional Functionality
These interceptors provide additional functionality to the monitor and router
- LogInterceptor
- SimpleURLRewritingInterceptor
- LoadbalancingInterceptor
Interceptor Chains
Transport Interceptors
Interceptors that are placed into a transport are invoked for all the messages that are flowing through that transport. See the transport bean in the monitor-beans.xml file.
Rule Interceptors
Interceptors that are placed into a rule are invoked when a message is matched by that rule. In the figure below there is a SimpleURLMappingInterceptor that manipulates the URI path of requests matching that rule.

Figure 2:
