Thursday, October 6, 2011

How to add JSON support to WSO2 WSAS

The WSO2 Web Services Application Server (WSAS) supports sending and receiving of messages in various formats. One such message format is JSON. This short article explains what needs done in order to use JSON with WSAS.
Date: Fri, 20th Mar, 2009
Level: Intermediate
Reads: 2320 Comments: 3 | Login or register to post comments
Kieth Chapman

WSO2 Inc.
You need to follow the following steps in order to have JSON support in WSAS:
  1. Get the axis2-json jar and drop it into $WSAS_HOME/webapps/ROOT/WEB-INF/plugins/
  2. Get the Jettison jar (Latest is 1.0.1) and drop it into $WSAS_HOME/webapps/ROOT/WEB-INF/plugins/Note : These jars need to be OSGI bundle jars. For simplicity I have attached OSGI bundles of this jars to this article. Please refer "How to build OSGi bundles using Maven Bundle Plugin" for details on how a OSGI bundle could be created from a jar.
  3. You need to make the underlining engine (Axis2) aware of the JSON related message builders. Add the following message builders to the messageBuilders section in the axis2.xml (found in $WSAS_HOME/conf/axis2.xml)
    <messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONOMBuilder"/>
    <messageBuilder contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishOMBuilder"/>
    <messageBuilder contentType="text/javascript" class="org.apache.axis2.json.JSONOMBuilder"/>
  4. You need to make the underlining engine (Axis2) aware of the JSON related Message Formatters. Add the following Message Formatters to the messageFormatters section in the axis2.xml which could be found in $WSAS_HOME/conf/axis2.xml
    <messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/>
    <messageFormatter contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishMessageFormatter"/>
    <messageFormatter contentType="text/javascript" class="org.apache.axis2.json.JSONMessageFormatter"/>
  5. Note :  This instructs the underlining engine (Axis2) to treat messages with the contentType application/json, application/json/badgerfish and text/json as JSON messages.

Applies To

WSAS 3.0 and above


Keith Chapman is a Senior Software Engineer at WSO2 - keith at wso2 dot com
org.wso2_.carbon.axis2_.json-1.4.1-wso2.jar12.12 KB
org.wso2_.carbon.jettison-1.0.1.jar52.59 KB's picture

I did everything in this

I did everything in this "HowTo" and it works with the Badgerfish convention but not with the mapped one.
When I use the Mapped convention I've got the followin error :
"Mapped formatted JSON with namespaces are not supported in Axis2. Make sure that your request doesn't include namespaces or use the Badgerfish convention".
Thanks in advance for any clues.'s picture

Hi krist_servansky

With the Axis2 JSON jar [1] and the Jettison jar[2] in repository/components/dropins, and repository/conf/axis2.xml with :
< messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter" />
< messageFormatter contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishMessageFormatter" />
< messageFormatter contentType="text/javascript" class="org.apache.axis2.json.JSONMessageFormatter" />
< messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONOMBuilder" />
< messageBuilder contentType="application/json/badgerfish" class="org.apache.axis2.json.JSONBadgerfishOMBuilder" />
< messageBuilder contentType="text/javascript" class="org.apache.axis2.json.JSONOMBuilder "/>
Stoped the server and started again, No errors found :)
But i'm i requesting it wrong ? The webservice call i'm making simple adds response=aplication/json
But the result still came in xml ( in Firefox and Chrome ). Any help ?
[1] http: //
[2] http: //
faluco's picture

JSON output in the WSAS 3.1.0

I configured the WSAS 3.1.0 as you described, used attached axis-json and jettison jars and added '&response=application/json' to the request but I am not able to get the json output.
Did I forget anything?

No comments:

Post a Comment