Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Apache CXF: Adding a Custom Interceptor to an Interceptor Chain

DZone's Guide to

Apache CXF: Adding a Custom Interceptor to an Interceptor Chain

Free Resource

The new Gartner Critical Capabilities report explains how APIs and microservices enable digital leaders to deliver better B2B, open banking and mobile projects.

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 new Gartner Critical Capabilities for Full Lifecycle API Management report shows how CA Technologies helps digital leaders with their B2B, open banking, and mobile initiatives. Get your copy from CA Technologies.

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}