Hear from Salesforce leaders on how to create and deploy Agentforce agents.
Contact Us 1-800-596-4880

Customize a Message Thrown by a SoapFault

APIkit for SOAP uses the Apache CXF Framework to manage items related to SOAP messages. There is no connection between the exceptions handled internally and Mule exception strategies. If you want to customize the message thrown by a SoapFault, you can use the CXF interceptor.

This document uses the following product versions:

  • Anypoint Studio 6.4.4

  • Mule EE 3.9.0

  • SoapKit 1.0.3

  • SoapUI 5.4.0

Locate the Interceptor Components

  1. Open Studio 6 and import the attached project custom-soap-fault.zip file.

  2. In the unzipped file, locate the interceptor SoapFaultOutInterceptor.java in the src/main/java/org/example folder.

    Customizing the message from a SoapFault consists of editing the SoapFaultOutInterceptor.java and changing this statement as shown below:

    final Throwable myCustomError = new Throwable("This is a custom error message !!!");

    In Studio, in the config file src/main/resource/cxf.xml are references to the interceptor:

Run the Application

Run the application from Studio.

*Run project soap* highlighted after right-clicking the application.

The application should deploy, and the following messages should appear in the Console:

**********************************************************************
* - - + APPLICATION + - - * - - + DOMAIN + - -  * - - + STATUS + - - *
**********************************************************************
* soap-SE-7813    * default                        * DEPLOYED        *
text

Send a SoapUI Request

  1. Using SoapUI, send a request to the deployed Mule app on port 8087.

    If you send an invalid XML, you see the SoapFault with the message customized in the SoapFaultOutInterceptor:

    SoapFault message in Studio.

    The console log should look like:

    ********** Start Custom SoapFault Interceptor ***********
    Original SoapFault:
    	Class: class com.ctc.wstx.exc.WstxParsingException
    	FaultCode :{http://schemas.xmlsoap.org/soap/envelope/}Client
    	Cause :Unexpected close tag </soapenv:Body>; expected </soapenv:Envelope>.
     at [row,col {unknown-source}]: [9,17]
    ********** End Custom SoapFault Interceptor ***********
    text
    Studio project structure with *SoapFaultOutInterceptor* highlighted.
  2. To get rid of the console exception, you can change the log severity.

  3. Include this line (already included but commented out) in the src/main/resources/log4j2.xml file:

    <!-- CXF, avoid log for invalid XML messages, SE-7813 changing the severity to ERROR -->
     <AsyncLogger name="org.apache.cxf.phase.PhaseInterceptorChain" level="ERROR"/>
    xml