This is the latest release in the 6.x.x family. For EI 7.0.0, click here.

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: Demonstrate the ability to expose a SOAP service over JSON by switching between JSON and XML/SOAP message formats using JavaScript and the Script mediator.

Sample 441 configuration
<definitions xmlns="">
    <proxy name="JSONProxy" transports="http https">
                <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
                <!-- transform the custom quote request into a standard quote requst expected by the service -->
                <script language="js"><![CDATA[
                    var symbol = mc.getPayloadJSON().symbol.toString();
                        <m:getQuote xmlns:m="http://services.samples">
                <header name="Action" value="urn:getQuote"/>
                <script language="js"><![CDATA[
                    var symbol = mc.getPayloadXML()..*::symbol.toString();
                    var price = parseFloat(mc.getPayloadXML()..*::last);
                            "Quote" : {
                                "Code" : symbol,
                                "Price" : price,
                                "Current" : {
                                    "High" : parseFloat(mc.getPayloadXML()..*::high),
                                    "Last" : parseFloat(mc.getPayloadXML()..*::last)
                            "Status" : (price >= 100 ? "OK" : "NOT-OK")
                <property name="messageType" scope="axis2" value="application/json"/>

The JavaScript specified by the Script mediator found in the inSequence performs the JSON to SOAP (XML) transformation as the SimpleStockQuoteService endpoint accepts SOAP. Similarly, the Script mediator in the outSequece performs the SOAP to JSON transformation.

1. Deploy the SimpleStockQuoteService in sample Axis2 server and start it on port 9000.

2. Create the above configuration and deploy it in the WSO2 EI profile, see Working with WSO2 Integration Studio.

Invoke the above proxy service with following request:

curl -v -X POST \
    -H "Content-Type:application/json" \
    -d '{"symbol":"WSO2", "ID":"StockQuote"}' \

If the invocation is successful, you will see a response similar to the following:


For more information about using JSON with the ESB, see Working with JSON Message Payloads. To see an example of converting JSON to XML using XSLT instead of JavaScript, see Sample 440: Converting JSON to XML Using XSLT. For additional examples of the Script mediator, see Using Scripts in Mediation (Script Mediator).

  • No labels