Enterprise Integration Zone is brought to you in partnership with:

I'm Singaram Subramanian, and I work with CSC India as a Software Developer. My blog is an attempt to share my learnings with all (mainly, for those who desperately mine google finding ways to solve problems, fix issues, learn about a Java/Open source software, or deciding on tough choices etc. during software development as I do). Singaram is a DZone MVB and is not an employee of DZone and has posted 36 posts at DZone. You can read more from them at their website. View Full User Profile

Apache CXF: Adding a Custom Interceptor to an Interceptor Chain

06.12.2012
| 8106 views |
  • submit to reddit

According to CXF docs,

Interceptors are the fundamental processing unit inside CXF. When a service is invoked, an InterceptorChain is created and invoked. Each interceptor gets a chance to do what they want with the message. This can include reading it, transforming it, processing headers, validating the message, etc.

When a CXF client invokes a CXF server, there is an outgoing interceptor chain for the client and an incoming chain for the server. When the server sends the response back to the client, there is an outgoing chain for the server and an incoming one for the client. Additionally, in the case of SOAPFaults, a CXF web service will create a separate outbound error handling chain and the client will create an inbound error handling chain.


To add an interceptor to an interceptor chain, you’ll want to add it to one of the Interceptor Providers.

MyInterceptor interceptor = new MyInterceptor();
provider.getInInterceptors().add(interceptor);


Some Interceptor providers inside CXF are:

* Client
* Endpoint
* Service
* Bus
* Binding


Steps to include a custom interceptor

1. Writing an interceptor by extending from either the AbstractPhaseInterceptor or one of its many subclasses such as AbstractSoapInterceptor.
2. Adding the custom interceptors into the interceptor chain either programmatically or through configuration.

More on this @ http://cxf.apache.org/docs/interceptors.html


If you’re looking for a practical example, you can visit this link, where Steve has written in detail about how he added an interceptor as per his requirement to the CXF fault chain: http://i-proving.ca/space/Technologies/Apache+CXF/Adding+an+interceptor+to+the+CXF+fault+chain

Published at DZone with permission of Singaram Subramanian, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)