Child pages
  • Sample 600 : Simple Message Transformation - Rule Mediator for Message Transformation

This documentation is for WSO2 ESB version 4.5.1. View documentation for the latest release.

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 4 Current »

Objective: Simple message transformation - Rule mediator for message transformation.

<!-- Simple rule based transformation (changing message )  -->
<definitions xmlns="http://ws.apache.org/ns/synapse">

    <sequence name="main">
        <in>

            <rule xmlns="http://wso2.org/carbon/rules">
                <source>soapBody</source>
                <target action="replace" xmlns:m0="http://services.samples" resultXpath="//m0:symbol"
                        xpath="//m0:getQuote/m0:request/m0:symbol">soapBody</target>
                <ruleSet>
                    <properties/>
                    <rule resourceType="regular" sourceType="inline">
                        <![CDATA[ package SimpleRoutingRules;

                        rule InvokeIBM
                        when
                        symbol: String()
                        eval( symbol.equals("MSFT") || symbol.equals("SUN") )
                        then
                        update(drools.getWorkingMemory().getFactHandle(symbol),"IBM");
                        end
                        ]]>
                    </rule>
                </ruleSet>
                <input namespace="http://services.samples" wrapperElementName="getQuote">
                    <fact xmlns:m0="http://services.samples" elementName="symbol" namespace="http://services.samples"
                          type="java.lang.String" xpath="//m0:getQuote/m0:request/m0:symbol/child::text()"/>
                </input>
                <output namespace="http://services.samples" wrapperElementName="getQuote">
                    <fact elementName="symbol" namespace="http://services.samples" type="java.lang.String"/>
                </output>
            </rule>
            <send>
                <endpoint>
                    <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                </endpoint>
            </send>

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

</definitions>

Prerequisites:

  • Start the Synapse configuration numbered 600: (i.e. ./wso2esb-samples.sh -sn 600)
  • Start the Axis2 server and deploy the SimpleStockQuoteService if not already deployed
  • In this sample , a simple transformation is happened . If the symbol is either SUN or MSFT , then it will changed into IBM in the SOAP envelope and then invoke the external service.

Run the client as

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

Or as

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

Then check the axis2server log or console

Wed July 04 16:33:05 IST 2012 samples.services.SimpleStockQuoteService :: Generating quote for : IBM
  • No labels