How to configure Native approach and XML Stream API base approach

How to use Native JSON support

If you need to expose your POJO services to support pure JSON requests as well as SOAP requests, then you need to go through the following process to do that with this new feature introduced into Axis2 JSON support.

Step 1 : Set in-out message receiver and in-only message receiver

You need to set org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver with http://www.w3.org/ns/wsdl/in-out message exchange pattern. Also with http://www.w3.org/ns/wsdl/in-only message exchange pattern, set org.apache.axis2.json.gson.rpc.JsonInOnlyRPCMessageReceiver.

eg.

            <messageReceivers>
                <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out"
                                 class="org.apache.axis2.json.gson.rpc.JsonRpcMessageReceiver"/>
                <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only"
                                 class="org.apache.axis2.json.gson.rpc.JsonInOnlyRPCMessageReceiver"/>
            </messageReceivers>
            

Step 2: Set message builder and message formatter

you need to edit axis2.xml in [AXIS2_HOME]/conf/ directory, to set org.apache.axis2.json.gson.JsonBuilder as message builder with application/json contentType to handle JSON requests and org.apache.axis2.json.gson.JsonFormatter as message formatter with application/json contentType to write response to wire as JSON format.

eg.

                  <messageBuilder contentType="application/json"
                                  class="org.apache.axis2.json.gson.JsonBuilder" />

                  <messageFormatter contentType="application/json"
                                    class="org.apache.axis2.json.gson.JsonFormatter" />
           

How to use XML stream API based approach

You can use this XML Stream API based approach with databinding services like ADB and xmlbeans as well as with normal POJO services. Follow the steps mentioned below to use this new feature introduced into Axis2 JSON support.

Step 1 : Set message builder and message formatter

You need to edit axis2.xml in [AXIS2_HOME]/conf/ directory, to set org.apache.axis2.json.gson.JsonBuilder as message builder with application/json contentType to handle JSON requests and, org.apache.axis2.json.gson.JsonFormatter as message formatter with application/json contentType to write response to wire as JSON format.

eg.

                <messageBuilder contentType="application/json"
                                class="org.apache.axis2.json.gson.JsonBuilder" />

                <messageFormatter contentType="application/json"
                                  class="org.apache.axis2.json.gson.JsonFormatter" />
                        
            

Step 2: Set inflow handlers

Remove RequestURIOperationDispatcher handler from dispatch phase and place it as the last handler in transport phase. Now add new JSONMessageHandler after the RequestURIOperationDispatcher. Finally transport phase would be like following,

            <phaseOrder type="InFlow">
                <!--  System predefined phases  -->
                <phase name="Transport">
                    -------------
                    <handler name="RequestURIOperationDispatcher"
                             class="org.apache.axis2.dispatchers.RequestURIOperationDispatcher"/>
                    <handler name="JSONMessageHandler"
                             class="org.apache.axis2.json.gson.JSONMessageHandler" />
                </phase>
                ------------
            </phaseOrder>