com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.

Sample 2: CBR with the Switch-Case Mediator Using Message Properties

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

Introduction

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.

Prerequisites

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

Building the sample

The XML configuration for this sample is as follows: 

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <sequence name="main">
        <in>
            <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>
                <case regex="MSFT">
                    <property name="symbol" value="Are you sure? - MSFT"/>
                </case>
                <default>
                    <!-- 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)"
                              xmlns:m0="http://services.samples"/>
                </default>
            </switch>
            <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')"/>
            </log>
            <!-- Send the messages where they are destined to (i.e. the 'To' EPR of the message) -->
            <send/>
        </in>
        <out>
            <send/>
        </out>
    </sequence>
</definitions>

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

To build the sample

  1. Start WSO2 EI with the sample 2 configuration. For instructions on starting a sample configuration, see Starting a sample.

    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 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
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.