Apache Axis2 can handle several message formats. JSON is just one of them. Axis2 supports two notations of JSON, they are known as mapped and Badgerfish. Namespaces are not handled in the mapped notation while the Badgerfish notations supports it.
The default Axis2 installation has all the binaries needed to process JSON messages but you need to enable it in order to use JSON. This can be done by adding the following sections to your axis2.xml.
Add the following section to the messageFormatters section in the axis2.xml,
And the following to the messageBuilders section of the axis2.xml
Now you are all set to invoke services as well as respond using JSON. You would notice that the notation of JSON used depends on the content-type of the message.
The default Axis2 installation has all the binaries needed to process JSON messages but you need to enable it in order to use JSON. This can be done by adding the following sections to your axis2.xml.
Add the following section to the messageFormatters section in the 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"/>
And the following to the messageBuilders section of the 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"/>
Now you are all set to invoke services as well as respond using JSON. You would notice that the notation of JSON used depends on the content-type of the message.
Hello, thank you for the post.
ReplyDeleteI dont understand how to invoke my service for to respond in json. For example, I call the service in the URL: http://localhost:8080/ws/services/people/hello, but always return xml objects.
Why?
you need to add content type as following:
ReplyDeletehttp://localhost:8080/ws/services/people/hello?content=application/json