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 the XSLT mediator and Enrich Mediator.

<definitions xmlns=""

    <proxy name="JSONProxy" transports="http https">
                <address uri="http://localhost:9000/services/SimpleStockQuoteService" format="soap11"/>
                <log level="full"/>
                <xslt key="in_transform"/>
                <property name="messageType" scope="axis2" value="text/xml"/>
                <header name="Action" scope="default" value="urn:getQuote"/>
                   <source xmlns:m0="http://services.samples" clone="true" xpath="//m0:getQuote"/>
                   <target type="body"/>
                <log level="full"/>
                <xslt key="out_transform"/>
                <property name="messageType" scope="axis2" value="application/json"/>

    <localEntry key="in_transform">
        <xsl:stylesheet xmlns:xsl=""
                        xmlns:m0="http://services.samples" version="2.0" exclude-result-prefixes="m0 fn">
            <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
            <xsl:template match="*">
                <xsl:element name="{local-name()}" namespace="http://services.samples">
                    <xsl:copy-of select="attribute::*"/>

    <localEntry key="out_transform">
        <xsl:stylesheet xmlns:xsl="" version="1.0">
            <xsl:output method="xml" version="1.0" encoding="UTF-8"/>
            <xsl:template match="*">
                <xsl:element name="{local-name()}">


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

3. Setup Synapse and the sample Axis2 client for JSON (Refer Synapse Samples Setup Guide for details)

Use following command to invoke the proxy service:

ant jsonclient -Daddurl=http://localhost:8280/services/JSONProxy

jsonclient sends the following JSON request to the above proxy service:


This request gets the following XML representation when it gets built in the ESB: (Take a look at the XML representation of JSON payloads within the ESB)


In the inSequence, the XSLT transformation in_transform transforms the above XML representation to the following XML by applying namespace declarations that are expected by the service.

<jsonObject xmlns="http://services.samples">

Finally the Enrich Mediator extracts the getQuote element from the above payload and attaches it as the first child of the current payload so that the final SOAP request that is sent to the service has the following format.

<soapenv:Envelope xmlns:soapenv="">
        <getQuote xmlns="http://services.samples">

We need to perform this sequence of transformations to the incoming JSON request to convert it and build the XML SOAP request expected by the service.  Note that the XSLT transformation in the outSequence (line 22) can be omitted because the JSON message formatter already knows how to format any XML payload to JSON.

The final response will look like the following:

         "lastTradeTimestamp":"Mon Aug 23 16:48:40 IST 2010",
         "name":"WSO2 Company",

For more information about using JSON with the ESB, see Working with JSON Message Payloads. For an example of how to convert JSON to XML using using JavaScript instead of XSLT, see Sample 441: Converting JSON to XML Using JavaScript.

  • No labels