Pergunta

While invoking a WSO2 data service over REST with content as JSON, I created a service which requires me to send a parametrized get, which in my case is

http://localhost:9765/services/TRAVEL_DSS_REST.HTTPEndpoint/Cost_Filter?PACKAGE_COST=1000

Though I am getting the response in XML format, on calling the REST service i do not get the response in JSON format.

Tried multiple options using curl: curl -i -H --header Content-Type:"application/json" "Accept: application/json" http://<ip>:<port>/services/TRAVEL_DSS_REST.HTTPEndpoint/Cost_Filter?PACKAGE_COST=1000

and Chrome Advanced Rest Client plugin.

Referred to the solution provided @ This stackoverflow link

Considering this i assume we have to send the GET parameters necessarily while hitting the WSO2-DS REST service encoded in the url to get JSON response.

I would be invoking this REST service on WSO2-DS via the WSO2-ESB, not sure how we can send the encoded request from the ESB to invoke the service, I want the message to be received in JSON format.

I have developed an REST API in the WSO2 ESB to invoke the DS, while i am able to see the response of directory service in the console, i am not able to see it in the client browser :( .. Here is my code block for the REST API

      `<api xmlns="http://ws.apache.org/ns/synapse" name="DSSClient" context="/DSSClient" hostname="localhost">
<resource methods="GET" uri-template="/{str1}">
    <inSequence>
        <property name="REST_URL_POSTFIX" expression="fn:concat('/Cost_Filter?PACKAGE_COST=',get-property('uri.var.str1'))" scope="axis2" type="STRING"/>
        <log level="full"/>
        <send>
            <endpoint>
                <address uri="http://10.203.245.47:9765/services/TRAVEL_DSS_REST.HTTPEndpoint/"/>
            </endpoint>
        </send>
    </inSequence>
    <outSequence>
        <log level="full"/>
        <log separator=",">
            <property name="response" value="***starting OUT Sequence****"/>
        </log>
        <property name="messageType" value="application/json/badgerfish" scope="axis2" type="STRING"/>
        <property name="ContentType" value="application/json/badgerfish" scope="axis2" type="STRING"/>
        <send/>
    </outSequence>
    <faultSequence/>
</resource>

`

Console Logs for the same are

[2013-05-23 11:12:12,833] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:19b3edc6-1203-4778-b14d-47bb3a66e959, Direction: response, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><VALID_PACKAGES xmlns="http://www.wso2.org/dss_rest"><PACAKAGE><PACKAGE_ID>2</PACKAGE_ID><PACKAGE_NAME>Adventure</PACKAGE_NAME></PACAKAGE></VALID_PACKAGES></soapenv:Body></soapenv:Envelope> [2013-05-23 11:12:12,834] INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous,WSAction: ,SOAPAction: ,MessageID: urn:uuid:19b3edc6-1203-4778-b14d-47bb3a66e959,Direction: response,response = ***starting OUT Sequence****

Please help me regarding the issue, if any in the code or any parameters need to be added to the conf.

Thanks, Ranjan

Foi útil?

Solução

I got a work around, This scenario works when i <property name="Content-Type" value="application/json/badgerfish" scope="transport" type="STRING"/> just before send mediator, you can see the response in the curl.

Outras dicas

In order to get the response in JSON,

Add following parameter to $CARBON_HOME/repository/conf/axis2.xml and restart server.

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

Invoke the service with curl as ,

curl -X GET http://<ip>:<port>/services/TRAVEL_DSS_REST.HTTPEndpoint/Cost_Filter?PACKAGE_COST=1000 -H Accept:application/json
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top