This is the latest release in the 6.x.x family. For EI 7.0.0, click here.

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

Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:

  • <PRODUCT_HOME>/repository/samples/ directory that includes all Integration profile samples is changed to <EI_HOME>/samples/service-bus/.
  • <PRODUCT_HOME>/repository/samples/resources/ directory that includes all artifacts related to the Integration profile samples is changed to <EI_HOME>/samples/service-bus/resources/.


This sample demonstrates the functionality of a Switch-Case Mediator. A message is passed through WSO2 EI in the Smart Client Mode. WSO2 EI acts as a gateway to accept all messages, writes and reads local properties on a message instance and then performs mediation based on the message properties or content.


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

Building the sample

The XML configuration for this sample is as follows: 

<definitions xmlns="">
    <sequence name="main">
            <switch source="//m0:getQuote/m0:request/m0:symbol" xmlns:m0="http://services.samples">
                <case regex="IBM">
                    <!-- the property mediator sets a local property on the *current* message -->
                    <property name="symbol" value="Great stock - IBM"/>
                <case regex="MSFT">
                    <property name="symbol" value="Are you sure? - MSFT"/>
                    <!-- it is possible to assign the result of an XPath expression as well -->
                    <property name="symbol"
                              expression="fn:concat('Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)"
            <log level="custom">
                <!-- the get-property() XPath extension function allows the lookup of local message properties
                    as well as properties from the Axis2 or Transport contexts (i.e. transport headers) -->
                <property name="symbol" expression="get-property('symbol')"/>
                <!-- the get-property() function supports the implicit message headers To/From/Action/FaultTo/ReplyTo -->
                <property name="epr" expression="get-property('To')"/>
            <!-- Send the messages where they are destined to (i.e. the 'To' EPR of the message) -->

This configuration file  synapse_sample_2.xml is available in the <EI_HOME>/samples/service-bus directory.

To build the sample

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

  2. 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 WSO2 EI instance and a back-end service deployed. In the next section, we will send a message to the back-end service through WSO2 EI 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

  • Run each of the following commands from the <EI_HOME>/samples/axis2Client directory, specifying IBM, MSFT and SUN as the stock symbols.

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

Analyzing the output

Analyze the mediation log on the WSO2 EI start-up console.

When the symbol IBM is requested, you will see that the case statements first case which is IBM in the synapse_sample_2.xml file is executed and a local property named symbol is set to Great stock - IBM. Subsequently, this local property value is looked up by the Log Mediator  and logged using the get-property()XPath extension function. 

The mediation log on the WSO2 EI start-up console will be as follows:

INFO LogMediator - symbol = Great stock - IBM, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService

When the symbol MSFT is requested, the mediation log on the WSO2 EI start-up console will be as follows:

INFO LogMediator - symbol = Are you sure? - MSFT, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService

When the symbol SUN is requested, the mediation log on the WSO2 EI start-up console will be as follows:

INFO LogMediator - symbol = Normal Stock - SUN, epr = http://localhost:9000/axis2/services/SimpleStockQuoteService
  • No labels