Chapter 6. Manipulating Interceptor Chains on the Fly
Abstract
Overview
Chain life-cycle
Getting the interceptor chain
Message.getInterceptorChain()
method shown in Example 6.1, “Method for getting an interceptor chain”. The interceptor chain is returned as a org.apache.cxf.interceptor.InterceptorChain
object.
Example 6.1. Method for getting an interceptor chain
InterceptorChain getInterceptorChain();
Adding interceptors
InterceptorChain
object has two methods, shown in Example 6.2, “Methods for adding interceptors to an interceptor chain”, for adding interceptors to an interceptor chain. One allows you to add a single interceptor and the other allows you to add multiple interceptors.
Example 6.2. Methods for adding interceptors to an interceptor chain
void add(Interceptor<? extends Message> i);
void add(Collection<Interceptor<? extends Message>> i);
Example 6.3. Adding an interceptor to an interceptor chain on-the-fly
- 1
- Instantiates a copy of the interceptor to be added to the chain.ImportantThe interceptor being added to the chain should be in either the same phase as the current interceptor or a latter phase than the current interceptor.
- 2
- Gets the interceptor chain for the current message.
- 3
- Adds the new interceptor to the chain.
Removing interceptors
InterceptorChain
object has one method, shown in Example 6.4, “Methods for removing interceptors from an interceptor chain”, for removing an interceptor from an interceptor chain.
Example 6.4. Methods for removing interceptors from an interceptor chain
void remove(Interceptor<? extends Message> i);
Example 6.5. Removing an interceptor from an interceptor chain on-the-fly
- 1
- Instantiates a copy of the interceptor to be removed from the chain.ImportantThe interceptor being removed from the chain should be in either the same phase as the current interceptor or a latter phase than the current interceptor.
- 2
- Gets the interceptor chain for the current message.
- 3
- Removes the interceptor from the chain.