Over a million developers have joined DZone.
Gold Partner

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

The Integration Zone is brought to you in partnership with CA Technologies. Download their eBook to learn more about API Strategy and Architecture.

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 Integration Zone is brought to you in partnership with CA Technologies. Use this model to create a sustainable API strategy that will help your organization adapt and succeed in the app economy.

Topics:
java,enterprise-integration,theory,apache,apache cxf

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 }}