【问题标题】:WSO2 DSS - Problems Calling REST, GET Operation for JSONWSO2 DSS - 为 JSON 调用 REST、GET 操作时出现问题
【发布时间】:2013-05-30 13:53:03
【问题描述】:

在通过 REST 调用 WSO2 数据服务时,内容为 JSON, 我创建了一个服务,它要求我发送一个参数化的 get,在我的例子中是

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

虽然我得到的是 XML 格式的响应,但在调用 REST 服务时我没有得到 JSON 格式的响应。

使用 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

和 Chrome Advanced Rest Client 插件。

参考@This stackoverflow link提供的解决方案

考虑到这一点,我假设我们必须在访问 url 中编码的 WSO2-DS REST 服务以获取 JSON 响应时发送 GET 参数。

我将通过 WSO2-ESB 在 WSO2-DS 上调用此 REST 服务,不知道如何从 ESB 发送编码请求以调用该服务,我希望以 JSON 格式接收消息。

我在 WSO2 ESB 中开发了一个 REST API 来调用 DS,虽然我能够在控制台中看到目录服务的响应,但我无法在客户端浏览器中看到它:( .. 这是我的 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>

`

相同的控制台日志是

[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****

请帮我解决这个问题,如果代码中的任何内容或任何参数需要添加到conf中。

谢谢, 兰詹

【问题讨论】:

    标签: json rest wso2 wso2carbon wso2dss


    【解决方案1】:

    我有一个解决方法,当我 &lt;property name="Content-Type" value="application/json/badgerfish" scope="transport" type="STRING"/&gt; 在发送中介之前,您可以在 curl 中看到响应。

    【讨论】:

      【解决方案2】:

      为了得到 JSON 格式的响应,

      将以下参数添加到 $CARBON_HOME/repository/conf/axis2.xml 并重新启动服务器。

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

      使用 curl as 调用服务,

      curl -X GET http://<ip>:<port>/services/TRAVEL_DSS_REST.HTTPEndpoint/Cost_Filter?PACKAGE_COST=1000 -H Accept:application/json
      

      【讨论】:

      • 感谢 Lakmali,该解决方案帮助我在 curl 中接收 JSON 响应,您能否在我无法从为调用 DS 而创建的 REST API 获得正确响应的其他部分帮助我。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多