This documentation is for WSO2 Enterprise Service Bus version 4.8.1 . View documentation for the latest release.

All docs This doc
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Next »

Introduction

This sample demonstrates the functionality of the Fault mediator (also called the Makefault mediator). Here a message is sent from the sample client to the back-end service through the ESB via two faulty mediation options, and then appropriate SOAP error responses are sent back to the client using the Send mediator.

Prerequisites

For a list of prerequisites, see Prerequisites to Start the ESB Samples.

Building the sample

The XML configuration for this sample is as follows: 

<definitions xmlns="http://ws.apache.org/ns/synapse">

    <sequence name="myFaultHandler">
        <makefault>
            <code value="tns:Receiver" xmlns:tns="http://www.w3.org/2003/05/soap-envelope"/>
            <reason expression="get-property('ERROR_MESSAGE')"/>
        </makefault>
        <send/>
    </sequence>

    <sequence name="main" onError="myFaultHandler">
        <in>
            <switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples">
                <case regex="MSFT">
                    <send>
                        <endpoint>
                            <address uri="http://bogus:9000/services/NonExistentStockQuoteService"/>
                        </endpoint>
                    </send>
                </case>
                <case regex="SUN">
                    <send>
                        <endpoint>
                            <address uri="http://localhost:9009/services/NonExistentStockQuoteService"/>
                        </endpoint>
                    </send>
                </case>
            </switch>
            <drop/>
        </in>

        <out>
            <send/>
        </out>
    </sequence>

</definitions>

This configuration file  synapse_sample_5.xml is available in the <ESB_HOME>/repository/samples directory. 

To build the sample

  1. Start the ESB with the sample 5 configuration. For instructions on starting a sample ESB configuration, see Starting the ESB with a sample configuration.

    The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."

  2. Start the Axis2 server. For instructions on starting the Axis2 server, see Starting the Axis2 server.

  3. Deploy the back-end service SimpleStockQuoteService. For instructions on deploying sample back-end services, see Deploying sample back-end services.

    Now you have a running ESB instance and a back-end service deployed. In the next section, we will send a message to the back-end service through the ESB using a sample client.

Executing the sample

The sample client used here is the Stock Quote Client, which can operate in several modes. For further details on this sample client and its operation modes, see Stock Quote Client.

To execute the sample client

  1. Run the following command from the <ESB_HOME>/samples/axis2Client directory to trigger a MSFT stock quote request to the back-end service.

    ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=MSFT
  2. Run the following command from the <ESB_HOME>/samples/axis2Client directory to trigger a SUN stock quote request to the back-end service.

    ant stockquote -Daddurl=http://localhost:9000/services/SimpleStockQuoteService -Dtrpurl=http://localhost:8280/ -Dsymbol=SUN

Analyzing the output

When the MSFT stock quote is requested, an unknown host exception is generated according to the XML configuration in  synapse_sample_5.xml.

<case regex="MSFT">
  <send>
     <endpoint>
         <address uri="http://bogus:9000/services/NonExistentStockQuoteService"/>
     </endpoint>
  </send> 
</case>

This error message is captured and returned to the original client as a SOAP fault. You will see the following response on the console.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode xmlns:tns="http://www.w3.org/2003/05/soap-envelope">tns:Receiver</faultcode>
            <faultstring>Error connecting to the back end</faultstring>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>

When the SUN stock quote is requested, a connection refused exception is generated according to the XML configuration in synapse_sample_5.xml.

This error message is captured and returned to the original client as a SOAP fault. You will see the following response on the console.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <soapenv:Fault>
            <faultcode xmlns:tns="http://www.w3.org/2003/05/soap-envelope">tns:Receiver</faultcode>
            <faultstring>Error connecting to the back end</faultstring>
        </soapenv:Fault>
    </soapenv:Body>
</soapenv:Envelope>
  • No labels