JSON (JavaScript Object Notation) Sample Guide

INTRODUCTION

This is a simple sample that demonstrates the functionality of the JSON Support in WSO2 Application Server, which comes from Apache axis2. Please refer to the references below for further information on how JSON work in axis2.

BUILDING THE SERVICE

  1. Start the WSO2AppServer server
  2. Switch to the JSON sample directory
  3. e.g. In MS Windows cd C:\wso2appserver-x.x.x\samples\JSON or in 
    	Linux cd wso2appserver-x.x.x/samples/JSON
  4. Type ant and press enter
  5. e.g. C:\wso2appserver-x.x.x\samples\JSON>ant or wso2appserver-x.x.x/samples/JSON$ ant
  6. Use "ant" command in the CARBON_HOME/samples/JSON/ to build the service.
  7. This will create the JSON service (JSONService.aar file) in the "services" directory and copy it to the <CARBON_HOME>/repository/deployment/server/axis2services directory. If you start AppServer, JSONService will be available as a deployed service.
  8. The WSDL for the service should be viewable at: http://<host>:<port>/services/JSONService?wsdl

RUNNING THE CLIENT

    Use the script run-client.sh or run-client.bat file to invoke the client using following optional parameters

       -help (For help on available options)
       -ct {Content type to be used}
            aj  (application/json)
            ajb (application/json/badgerfish)
    
       	e.g: ./run-client.sh -ct ajb

In the JSON sample an xml element is sent to AppServer via the client.

<echo><ns:value xmlns:ns="http://services.wsas.training.wso2.org">Hello JSON Service</ns:value></echo>
You can change the "http port" in "src/org/wso2/appserver/sample/json/client/JSONClient.java" and monitor the JSON object that passed through to AppServer, using a capuring tool such as tcp monitor.

json_object_captured

Figure 1: JSON Object passing captured from tcp monitor.