JSON Support
This sample demonstrates the WSO2 Application Server's support for JSON, which comes from Apache axis2.
Note:
For more information on how JSON works in axis2, refer to the following external URLs:
1. http://wso2.org/library/768
2. http://axis.apache.org/axis2/java/core/docs/json_support.html
Building the Service
To build the samples you need Apache Ant build tool.
The steps are as follows.
1. Install and run the WSO2 Application Server. Refer to the Installation Guide for instructions.
2. In a command prompt, switch to the sample directory.
For example, in Wndows, cd <AS_HOME>\samples\JSON
3. From there, type ant .
This will create the JSON service (JSONService.aar file) in <AS_HOME>/repository/deployment/server/axis2services directory. If you start the WSO2 Application Server, you can view the "JSONService" service on "Deployed Services" window. (Main -> Services -> List).
The WSDL for the service should be viewable at: http://<host>:<port>/services/JSONService?wsdl
Running the Client
Use the script run-client.sh (in Linux) or run-client.bat file (in Windows) to invoke the client using following optional parameters.
-help (For help on available options) -e : Endpoint URL of the service. -ct {Content type to be used} aj (application/json) ajb (application/json/badgerfish)
For example, ./run-client.sh -ct ajb
In the JSON sample, an XML element is sent to the Application Server 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 " of the variable String epr = " http://localhost:9763/services/JSONService " in <AS_HOME>/samples/JSON/src/org/wso2/appserver/sample/json/client/JSONClient.java and monitor the JSON object that is passed through to the Application Server, using a capturing tool such as tcp monitor.
Image: JSON Object passing captured from tcp monitor.