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 by using JSONStreamBuilder and JSONStreamFormatter message builder/formatter pair for JSON.

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

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

2. Modify the message builder and the message formatter for application/json content type in the /repository/conf/axis2/axis2.xml file.

  • To change the message builder,
    Locate the messageBuilders  section and disable the existing message builder for application/json and enable org.apache.axis2.json.JSONStreamBuilder message builder
  • To change the message formatter,
    Locate the messageFormatters  section and disable the existing message formatter for application/json and enable org.apache.axis2.json.JSONStreamFormatter message formatter

3. Replace the configuration of Sample 441 (found in ESB_HOME/repository/samples/synapse_sample_441.xml) with the configuration shown above.

4. Start WSO2 ESB with the sample configuration 441 (i.e. wso2esb-samples -sn 441).

Invoke the proxy service as follows

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

If the invocation was successful, you must see a reply similar to the following

< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Wed, 07 Aug 2013 06:34:47 GMT
< Server: WSO2-PassThrough-HTTP
< Transfer-Encoding: chunked
* Connection #0 to host localhost left intact
* Closing connection #0
{"Quote" : {"Current" : {"High" : -61.53602401623976, "Last" : 62.32682938796667}, "Code" : "WSO2", "Price" : 62.32682938796667}, "Status" : "NOT-OK"}




  • No labels