This documentation is for WSO2 Enterprise Service Bus version 4.8.1 . View documentation for the latest release.
Skip to end of metadata
Go to start of metadata

Objective: Script mediators using Ruby (inline Ruby script)

<!-- Using In-lined Ruby scripts for mediation -->
<definitions xmlns="http://ws.apache.org/ns/synapse">
    <in>
        <script language="rb">
            <![CDATA[
                require 'rexml/document'
                include REXML
                newRequest= Document.new '<m:getQuote xmlns:m="http://services.samples/xsd"><m:request><m:symbol>...test...</m:symbol></m:request></m:getQuote>'
                newRequest.root.elements[1].elements[1].text = $mc.getPayloadXML().root.elements[1].get_text
                $mc.setPayloadXML(newRequest)
            ]]>
        </script>
        <send>
            <endpoint>
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
        </send>
    </in>
    <out>
        <script language="rb">
            <![CDATA[
                require 'rexml/document'
                include REXML
                newResponse = Document.new '<m:CheckPriceResponse xmlns:m="http://services.samples/xsd"><m:Code></m:Code><m:Price></m:Price></m:CheckPriceResponse>'
                newResponse.root.elements[1].text = $mc.getPayloadXML().root.elements[1].elements[1].get_text
                newResponse.root.elements[2].text = $mc.getPayloadXML().root.elements[1].elements[2].get_text
                $mc.setPayloadXML(newResponse)
            ]]>
        </script>
        <send/>
    </out>
</definitions>

Prerequisites:

  • This sample uses Ruby, so first set up Ruby support as described at Configuring the ESB for Script Mediator Support.
  • Start the Synapse configuration numbered 354: i.e. wso2esb-samples -sn 354
  • Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

This sample is functionally equivalent to Sample 353.

Run the client with

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

Database Interactions in Mediation (DBLookup / DBReport)

Following database mediators use Derby in a client/server configuration by using the network server. Therefore, to proceed with the following samples, you need a working Derby database server and you have to follow the steps in ESB Sample Setup before going through the samples.

  • No labels