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

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

Objective: Introduction to simple rule based routing.

Code Block
<!-- Simple rule based routing  of messages - same as filter mediator -->
<definitions xmlns="">
            <ruleset >
                    <package name="SimpleRoutingRules"
                             xs:schemaLocation=" drools-4.0.xsd">
                        <import name="org.apache.synapse.MessageContext"/>
                        <rule name="Invoke IBM ">
                                <pattern object-type="MessageContext" identifier="mc"></pattern>
                                <pattern object-type="String" identifier="symbol"></pattern>
                    <property name="source" value="xml"/>
            <session type="stateless"/>
                <fact name="mc" type="context"/>
                <fact name="symbol" type="java.lang.String"
                        <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>



  • Start the Synapse configuration numbered 600: (i.e. ./ -sn 600)
  • Start the Axis2 server and deploy the SimpleStockQuoteService if not already deployed.

Run the client as

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

Or as

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

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


Code Block
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".