Apache CXF: Adding a custom interceptor to an interceptor chain


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

About these ads

4 comments

  1. [...] Apache CXF: Adding a custom interceptor to an interceptor chain (singztechmusings.wordpress.com) [...]

  2. [...] Apache CXF: Adding a custom interceptor to an interceptor chain (singztechmusings.wordpress.com) [...]

  3. [...] Apache CXF: Adding a custom interceptor to an interceptor chain (singztechmusings.wordpress.com) [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 27 other followers

%d bloggers like this: