Software Development

Log Unencrypted SoapFault Messages in Apache CXF

This post shows how to log unencrypted SoapFault messages from Apache CXF  in client applications. These applications use WS-Security for encryption and decryption. Note that this write-up assumes the reader is familiar with the more advanced stuff in SOAP-based web services.

Java and Apache CXF Requirements

When we wrote the codes, we used the following items. We have not tested with the later versions of the items.

  • SOAP 1.2
  • Java 8
  • Apache CXF 2.7.18
    • cxf-bundle version 2.7.18
  • Encryption and decryption on the client application work

Unencrypted SoapFault Fault Sample From Apache CXF

Consider the following log fragment. It shows the stack trace of an Exception.

Usually, there are no other details logged except for the short message plus the faultCode and an encrypted SOAP response message (SoapFault) with Response-Code: 500.

Apache CXF Fault Interceptors

To log the unencrypted SoapFault messages, we must configure our org.apache.cxf.endpoint.Client object to use interceptors to handle faults. For our purpose, we can use 2 interceptors – a custom interceptor and org.apache.cxf.binding.soap.interceptor.Soap12FaultInInterceptor.

Using Apache CXF Soap12FaultInInterceptor

This interceptor generally sets the “Exception” content of the incoming SoapMessage object. The incoming message is basically an Exception (a Fault). See line 47 on the screenshot below.

For SOAP1.1, please use org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.

A Custom Apache CXF Interceptor to log Unencrypted SoapFault

In this custom interceptor, we used Phase.POST_INVOKE. For Soap12FaultInInterceptor,  the codes use the “unmarshalled” String object. This means that our custom interceptor is used after the Soap12FaultInInterceptor.

Configure Apache CXF Client

We then need to configure our Client object by adding the interceptor objects to the “InFault” interceptors list.

Now, when we encounter a SoapFault in Apache CXF, we get the following sample log output.

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like