Sunday, April 15, 2012

Configuring Axis 2 to enable JSON

Edit conf/axis2.xml, find for <messageFormatters>


<messageFormatters>
        <messageFormatter contentType="application/x-www-form-urlencoded"
                          class="org.apache.axis2.transport.http.XFormURLEncodedFormatter"/>
        <messageFormatter contentType="multipart/form-data"
                          class="org.apache.axis2.transport.http.MultipartFormDataFormatter"/>
        <messageFormatter contentType="application/xml"
                          class="org.apache.axis2.transport.http.ApplicationXMLFormatter"/>
        <messageFormatter contentType="text/xml"
                          class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
        <messageFormatter contentType="application/soap+xml"
                          class="org.apache.axis2.transport.http.SOAPMessageFormatter"/>
         
        <!-- Enabling JSON -->       
        <messageFormatter contentType="application/json"
                         class="org.apache.axis2.json.JSONMessageFormatter"/>
    </messageFormatters>

Find for  <messageBuilders>

<messageBuilders>
        <messageBuilder contentType="application/xml"
                        class="org.apache.axis2.builder.ApplicationXMLBuilder"/>
        <messageBuilder contentType="application/x-www-form-urlencoded"
                        class="org.apache.axis2.builder.XFormURLEncodedBuilder"/>
        <messageBuilder contentType="multipart/form-data"
                        class="org.apache.axis2.builder.MultipartFormDataBuilder"/>
                         
        <!-- Enabling JSON -->               
        <messageBuilder contentType="application/json"
                         class="org.apache.axis2.json.JSONOMBuilder"/>
                         
    </messageBuilders>

Add some library if is not exist in the lib folder
  • axis2-json-1.6.0.jar
  • jettison-1.0-RC2.jar
You may need this axis2-transport JAR files
  • axis2-transport-http.jar
  • axis2-transport-local.jar
  • axis2-transport-tcp.jar

No comments: