Over a million developers have joined DZone.
Platinum Partner

Apache CXF: Adding a Custom Interceptor to an Interceptor Chain

The Integration Zone is brought to you in partnership with 3scale. Take control of your APIs and get a free t-shirt when you complete the 3step Challenge

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

The Integration Zone is brought to you in partnership with 3scale. Learn how API providers have changed the way we think about integration in The Platform Vision of API Giants.

Topics:

Published at DZone with permission of Singaram Subramanian , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}