This documentation is for WSO2 Data Services Server 3.1.1. View the home page of the latest release.

Unknown macro: {next_previous_link3}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 10 Next »

WSO2 Data Services Server provides a mechanism to expose enterprise data as web services or as REST resources. Given below is an example of how you can configure DSS to allow users to receive messages in JSON format instead of XML.

The default setting in DSS is to use XML as the data format for sending and receiving messages. If you want to change this to another format, the system has to be manually configured by enabling 'content negotiation'.

To receive JSON responses from DSS, the 'content negotiation' property should be enabled in the  axis2.xml and axis2_client.xml files which are stored in the <DSS_HOME>/repository/conf directory. Note that this setting (JSON content negotiation) cannot be enabled as the default setting. After content negotiation is enabled, you must send requests to the server by adding Accept:Application/json” to the request header, and as a result, DSS will return the response in JSON format.

To change the axis2.xml file

  1.  Open the axis2.xml file stored in <DSS_HOME>/repository/conf/axis2 directory.
  2. Add <parameter name=“httpContentNegotiation”>true</parameter> to the list of parameters. Note that this parameter is not available by default in the axis2.xml file and requires to be added manually.

    <axisconfig name="AxisJava2.0">
    
    
        <!-- ================================================= -->
        <!-- Globally engaged modules -->
        <!-- ================================================= -->
        <module ref="addressing"/>
    
        <!-- ================================================= -->
        <!-- Parameters -->
        <!-- ================================================= -->
        <parameter name="hotdeployment">true</parameter>
        <parameter name="hotupdate">true</parameter>
        <parameter name="enableMTOM" locked="false">optional</parameter>
        <parameter name="cacheAttachments">true</parameter>
        <parameter name="attachmentDIR">work/mtom</parameter>
        <parameter name="sizeThreshold">4000</parameter>
        <parameter name=“httpContentNegotiation”>true</parameter>
        <parameter name=“EnableChildFirstClassLoading”>${childfirstCL}</parameter>

To change the axis2_client.xml file

  1. Open the axis2_client.xml file stored in <DSS_HOME>/repository/conf/axis2 directory.
  2. Set the 'content negotiation' parameter to True. Note that this parameter is already available in the axis2_client.xml and it is only required to be enabled.

    <axisconfig name="AxisJava2.0">
        <!-- ================================================= -->
        <!-- Parameters -->
        <!-- ================================================= -->
        <parameter name="hotdeployment">true</parameter>
        <parameter name="hotupdate">false</parameter>
        <parameter name="enableMTOM">false</parameter>
    
    
        <!-- commons-http-client defaultMaxConnPerHost -->
        <parameter name="defaultMaxConnPerHost">500</parameter>
        <!-- commons-http-client maxTotalConnections -->
        <parameter name="maxTotalConnections">15000</parameter>
    
    
        <!--If turned on with use the Accept header of the request to determine the contentType of the
        response-->
        <parameter name=“httpContentNegotiation">True</parameter>

Test the JSON Configuration

After you have changed the axis2.xml file and axis2_client.xml files as explained above, use the ResourceSample, which is a sample available in your DSS distribution. This sample explains how data is exposed as a REST resource using DSS. Once this sample is deployed, send a request to the server using  CURL by adding Accept:Application/json” to the request header as shown below. Go to Exposing Data as REST-Style Resources for instructions on how to run this sample.

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