Powered By Blogger

Dec 29, 2014

Get a JSON response with WSO2 DSS


WSO2 Data Services Server supports for both XML and JSON outputs and in order to receive the message as JSON you need to change following configurations.
You can achieve this by enabling the 'content negotiation' property in the axis2.xml file and axis2_client.xml file. Also you should send the requests to the server by adding the "Accept:Application/json" to the request header, and as a result, DSS will return the response in JSON format. Please follow the below steps 

1. In axis2.xml file at <DSS_HOME>/repository/conf/axis2, include the following property 

<parameter name="httpContentNegotiation>true</parameter> 

2. In axis2_client.xml file at <DSS_HOME>/repository/conf/axis2 enable the following property 

<parameter name="httpContentNegotiation>true</parameter> 

3. When sending the request please make sure to add the "Accept:Application/json" to the request header 

Note that if you are using tenant, then the above parameter need to be set in 'tenant-axis2.xml' as well.
Now you can use the ResourceSample, which is a sample available in your DSS distribution to test the result. Send a request to the server using  CURL by adding “Accept:Application/json” to the request header as shown below.

curl -X GET -H "Accept:application/json" http://localhost:9763/services/samples/ResourcesSample.HTTPEndpoint/product/S10_1678

No comments:

Post a Comment