Saturday, March 1, 2014

How to get a JSON response with WSO2 Data Services Server (wso2dss) ?

Latest version of DSS can be downloaded from here. (At the moment it's wso2dss-3.1.1).

Data Services Server support for both XML and JSON outputs. In order to get a JSON output, you need to change following configurations.

Add following parameter to 'axis2.xml' and in 'axis2_client.xml'. (In axis2_client.xml this parameter is already there, but its default value is set to false. These two files are located in '{DSS_HOME}/repository/conf/axis2/' directory).

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

Note that if you are using tenant, then the above parameter need to be set in 'tenant-axis2.xml' as well.

Restart the server. We are done.

We need to use content-negotiation when doing the requests. i.e We need to pass 'Accept' header with the request. Example request done for customersInBoston operation in the RDBMSSample is given bellow. (This sample 'RDBMSSample' service is deployed in server by default).

curl -v -H "Accept:application/json" http://localhost:9783/services/samples/RDBMSSample/customersInBoston

{"customers":{"customer":[{"customer-name":"","contact-last-name":"Yoshido","contact-first-name":"Juri","phone":"6175559555","city":"Boston","country":"USA"},{"customer-name":"Diecast Collectables","contact-last-name":"Franco","contact-first-name":"Valarie","phone":"6175552555","city":"Boston","country":"USA"}]}}