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

Objective: Demonstrate the ability to switch between JSON and XML/SOAP content interchange formats.

<definitions xmlns=""

    <proxy name="JSONProxy" transports="http https">
                <address uri="http://localhost:9000/services/SimpleStockQuoteService"/>
                <log level="full"/>
                <xslt key="in_transform"/>
                <property name="messageType" scope="axis2" value="text/xml"/>
                <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. Start Synapse with the sample configuration 440 (i.e. wso2esb-samples -sn 440).

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

Invoke the client as follows.

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

JSON client will send a stockquote request to Synapse using the JSON content interchange format. Synapse will trnasform it into a SOAP request and forward to the Axis2 server. The SOAP response from the Axis2 server will be converted into a JSON message and sent back to the JSON client.

You may use a tool like TCPMon to monitor the JSON requests sent over the wire. A sample JSON request and response is shown below:

{"getQuoteResponse":{"return":{"change":3.853593376681722,"earnings":12.802850763714854,"high":67.92488310190126,"last":66.14619264746406,"lastTradeTimestamp":"Mon Aug 23 16:48:40 IST 2010","low":-66.04000424423522,"marketCap":-9334516.42324327,"name":"IBM Company","open":-64.61950137150009,"peRatio":-19.78600441437058,"percentageChange":5.411779328273005,"prevClose":71.2075112994578,"symbol":"IBM","volume":16842}}}

Modifying URLs with URL Rewrite Mediator

URL rewrite mediator enables modifying URL values in the message. The input URL could be taken from the 'To' header of the message or from a property available on the message. Once the input URL is selected, a series of user defined rewrite rules will be evaluated on the message. Depending on the outcome of these rule evaluations, the URL will be modified and set on the message.

URL rewrite mediator breaks the URL down to seven segments.

  • Protocol
  • User information
  • Hostname
  • Port
  • Path
  • Query
  • Reference parameter

Note that this breakdown is inline with the URI specification (RFC2396). URL rewrite mediator enables rewriting each of the above segments separately and finally combining them to get the final URL value. It also supports rewriting the entire URL string at once.

  • No labels