This documentation is for WSO2 Enterprise Service Bus version 4.7.0 . View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

Introduction

This sample demonstrates the functionality of 'makefault' mediator.  It sends a message from a sample client to a back-end service through the ESB through 2 faulty mediation options and sends back appropriate SOAP error responses to the client.

Prerequisites

For a list of prerequisites, see the Prerequisites section in ESB Samples Setup.

Building the Sample

1. Start the ESB with sample 5 configuration using the instructions given in Starting Sample ESB Configurations.

2. A message should appear in the command or text Linux console stating the server started successfully.

3. The synapse configuration in the ESB used for message mediation in this sample is provided in <ESB_HOME>/repository/samples/synapse_sample_5.xml as shown below:

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

        <property name="RESPONSE" value="true"/>
        <header name="To" expression="get-property('ReplyTo')"/>
        <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>

4. Deploy the back-end service 'SimpleStockQuoteService' and start the Axis2 server using the instructions given in section Starting Sample Back-End Services.

5. 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 'Stock Quote Client' which can operate in several modes. For instructions on this sample client and its operation modes, refer to Stock Quote Client

1. Run the following ant command from <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. An unknown host exception should be generated according to the synapse_sample_5.xml specified above.

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

3. This error message is captured and returned to the original client as a SOAP fault.

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

4. Run the following ant command 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

5. A connection refused exception should be generated according to the synapse_sample_5.xml specified above.  

6. This error message is captured and returned to the original client as a SOAP fault.

<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