This documentation is for WSO2 Enterprise Integrator version 6.0.0 . View documentation for the latest release in the 6.x.x family and the latest release in the 7.x.x family.

All docs This doc
Skip to end of metadata
Go to start of metadata

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

Objective: Script mediators using Ruby

<definitions xmlns="">

    <localEntry key="stockquoteScript" src="file:repository/samples/resources/script/stockquoteTransform.rb"/>
        <!-- transform the custom quote request into a standard quote request expected by the service -->
        <script language="rb" key="stockquoteScript" function="transformRequest"/>

        <!-- send message to real endpoint referenced by name "stockquote" and stop -->
            <endpoint name="stockquote">
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
        <!-- transform the standard response back into the custom format the client expects -->
        <script language="rb" key="stockquoteScript" function="transformResponse"/>
require 'rexml/document'
include REXML

def transformRequest(mc)
   newRequest= '<m:getQuote xmlns:m="http://services.samples/xsd">'<<
   newRequest.root.elements[1].elements[1].text = mc.getPayloadXML().root.elements[1].get_text

def transformResponse(mc)
   newResponse = '<m:CheckPriceResponse xmlns:m="http://services.samples/xsd"><m:Code>' <<
   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


This sample uses Ruby so first set up Ruby support as described in Configuring the ESB for Script Mediator Support .

  • Start the Synapse configuration numbered 353: i.e. wso2ei-samples -sn 353
  • Start the Axis2 server and deploy the SimpleStockQuoteService if not already done

This sample is functionally equivalent to sample # 350 (#351 and #8) but instead uses a Ruby script using the JRuby interpreter. The script has two functions, 'transformRequest' and 'transformResponse', and the Synapse configuration specifies to be invoked when used. Execute the stock quote client to send a custom stock quote as per Sample 350 and check the received stock quote response.

  • No labels