Skip to content

Using Fault Sequences

WSO2 Micro Integrator provides fault sequences for dealing with errors. Whenever an error occurs, the mediation engine attempts to provide as much information as possible on the error to the user by initializing the following properties on the erroneous message:


Synapse configuration

Following are the integration artifacts that we can used to implement this scenario. See the instructions on how to build and run this example.

  • Proxy service:

    <proxy xmlns="" name="FaultTestProxy" startOnLoad="true" transports="http https">
                <switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples">
                    <case regex="IBM">
                            <endpoint><address uri="http://localhost:9000/services/SimpleStockQuoteService"/></endpoint>
                    <case regex="MSFT">
                            <endpoint key="bogus"/>
                    <case regex="SUN">
                        <sequence key="sunSequence"/>

  • Mediation sequences:

    <sequence xmlns="" name="fault">
        <log level="custom">
            <property name="text" value="An unexpected error occured"/>
            <property name="message" expression="get-property('ERROR_MESSAGE')"/>
    <sequence xmlns="" name="sunErrorHandler">
        <log level="custom">
            <property name="text" value="An unexpected error occured for stock SUN"/>
            <property name="message" expression="get-property('ERROR_MESSAGE')"/>
    <sequence xmlns="" name="sunSequence" onError="sunErrorHandler">
            <endpoint key="sunPort"/>

Note how the ERROR_MESSAGE property is being used to get the error message text. Within the fault sequence, you can access these property values using the get-property XPath function. The following log mediator logs the actual error message:

<log level="custom">  
    <property name="text" value="An unexpected error occured"/>
    <property name="message" expression="get-property('ERROR_MESSAGE')"/>

Build and run

Create the artifacts:

  1. Set up WSO2 Integration Studio.
  2. Create an ESB Solution project.
  3. Create the proxy service, and the mediation sequences with the configurations given above.
  4. Deploy the artifacts in your Micro Integrator.

Set up the back-end service:

  1. Download the stockquote_service.jar.
  2. Open a terminal, navigate to the location of the downloaded service, and run it using the following command:

    java -jar stockquote_service.jar

Send a request to invoke the proxy service:

POST http://localhost:8290/services/FaultTestProxy HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "urn:mediate"
Content-Length: 263
Host: Chanikas-MacBook-Pro.local:8290
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="">
   <soapenv:Header />
      <m0:getQuote xmlns:m0="http://services.samples">

The following line is logged:

INFO {org.apache.synapse.mediators.builtin.LogMediator} - text = An unexpected error occured for stock SUN, message = Couldn't find the endpoint with the key : sunPort