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 2 Next »

Objective: Introduction to simple rule based routing.

<!-- Simple rule based routing  of messages - same as filter mediator -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <in>
        <rule>
            <ruleset >
                <source>
                    <package name="SimpleRoutingRules"
                             xmlns="http://drools.org/drools-5.0"
                             xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
                             xs:schemaLocation="http://drools.org/drools-5.0 drools-4.0.xsd">
                        <import name="org.apache.synapse.MessageContext"/>
                        <rule name="Invoke IBM ">
                            <lhs>
                                <pattern object-type="MessageContext" identifier="mc"></pattern>
                                <pattern object-type="String" identifier="symbol"></pattern>
                                <eval>symbol.equals("IBM")</eval>
                            </lhs>
                            <rhs>mc.setProperty("execute_children","true");</rhs>
                        </rule>
                    </package>
                </source>
                <creation>
                    <property name="source" value="xml"/>
                </creation>
            </ruleset>
            <session type="stateless"/>
            <facts>
                <fact name="mc" type="context"/>
                <fact name="symbol" type="java.lang.String"
                      expression="//m0:getQuote/m0:request/m0:symbol/child::text()"
                      xmlns:m0="http://services.samples"/>
            </facts>
            <childMediators>
                <send>
                    <endpoint>
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                    </endpoint>
                </send>
                <drop/>
            </childMediators>
        </rule>
    </in>
    <out>
        <send/>
    </out>

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

Run the client as

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

Or as

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

Then, you will get stock quote price in the client side.

In this sample , with in the rule mediator , the value, which is extracted from the SOAP envelope using XPath '//m0:getQuote/m0:request/m0:symbol', is added to the rule engine as a string fact . The message context property named "execute_children" is to indicate it is need to execute the child mediators of rule mediator. That property is set only if the symbol is IBM.

Now use following commands

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

and

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

Then , you will get errors . This is because , 'symbol' is not equal to "IBM".

  • No labels