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

Apache CXF: How Message Processing Happens and What’s the Role of Interceptor?

DZone's Guide to

Apache CXF: How Message Processing Happens and What’s the Role of Interceptor?

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.

When a Apache CXF developed consumer invokes a remote service the following message processing sequence is started:

1. The Apache CXF runtime creates an outbound interceptor chain to process the request.

2. If the invocation starts a two-way message exchange, the runtime creates an inbound interceptor chain and a fault processing interceptor chain.

3. The request message is passed sequentially through the outbound interceptor chain. Each interceptor in the chain performs some processing on the message. For example, the Apache CXF supplied SOAP interceptors package the message in a SOAP envelope.

4. If any of the interceptors on the outbound chain create an error condition the chain is unwound and control is returned to the application level code. An interceptor chain is unwound by calling the fault processing method on all of the previously invoked interceptors. 5. The request is dispatched to the appropriate service provider.

6. When the response is received, it is passed sequentially through the inbound interceptor chain.
Note: If the response is an error message, it is passed into the fault processing interceptor chain.

7. If any of the interceptors on the inbound chain create an error condition, the chain is unwound.

8. When the message reaches the end of the inbound interceptor chain, it is passed back to the application code.

 


When a Apache CXF developed service provider receives a request from a consumer, a similar process takes place:

1. The Apache CXF runtime creates an inbound interceptor chain to process the request message.

2. If the request is part of a two-way message exchange, the runtime also creates an outbound interceptor chain and a fault processing interceptor chain.

3. The request is passed sequentially through the inbound interceptor chain.

4. If any of the interceptors on the inbound chain create an error condition, the chain is unwound and a fault is dispatched to the consumer. An interceptor chain is unwound by calling the fault processing method on all of the previously invoked interceptors.

5. When the request reaches the end of the inbound interceptor chain, it is passed to the service implementation.

6. When the response is ready it is passed sequentially through the outbound interceptor chain.
Note: If the response is an exception, it is passed through the fault processing interceptor chain.

7. If any of the interceptors on the outbound chain create an error condition, the chain is unwound and a fault message is dispatched.

8. Once the request reaches the end of the outbound chain, it is dispatched to the consumer.

 

Message Flow On Server Side

 

Message Flow On Client Side

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:
java ,enterprise-integration ,theory ,apache ,apache cxf

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}