WSO2 ESB中的API仅返回JSON的第一个节点?

时间:2016-08-02 19:52:18

标签: json rest wso2 wso2esb

我在WSO2企业服务总线中创建了一个REST API。 API调用SoapUI上的模拟服务,返回带有2个节点的JSON:

{
    "customer" : {
        "value1": "2312",
        "value2": "3214",
        "value3": "4214"
    },
    "msg" : "error"
}

ESB应返回此JSON,但它始终忽略第二个节点(" msg")并仅返回第一个节点。

我已经改变了位置,就像这样,但它不起作用:

{
    "msg" : "error",
    "customer" : {
        "value1": "2312",
        "value2": "3214",
        "value3": "4214"
    }
}

API非常简单,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/test1" name="test" xmlns="http://ws.apache.org/ns/synapse">
  <resource methods="POST" protocol="http">
    <inSequence>
      <send>
        <endpoint key="conf:/endpoint.xml"/>
      </send>
    </inSequence>
    <outSequence/>
    <faultSequence/>
  </resource>
</api>

我已经检查了模拟并且它正在回答ESB的权利

为什么我的API只返回第一个节点?

我的电汇记录:

[2016-08-03 14:04:14,343] DEBUG - wire >> "POST /CustomerHSF/retrieveCustomerHSF HTTP/1.1[\r][\n]"
[2016-08-03 14:04:14,344] DEBUG - wire >> "HOST: localhost:8283[\r][\n]"
[2016-08-03 14:04:14,345] DEBUG - wire >> "content-type: application/json[\r][\n]"
[2016-08-03 14:04:14,345] DEBUG - wire >> "content-length: 100[\r][\n]"
[2016-08-03 14:04:14,345] DEBUG - wire >> "[\r][\n]"
[2016-08-03 14:04:14,345] DEBUG - wire >> "{[\r][\n]"
[2016-08-03 14:04:14,345] DEBUG - wire >> ""nomCliente": "SILVA",[\r][\n]"
[2016-08-03 14:04:14,345] DEBUG - wire >> ""tipoPessoa": "FIS",[\r][\n]"
[2016-08-03 14:04:14,345] DEBUG - wire >> ""dscEmail": "google@google.com"[\r][\n]"
[2016-08-03 14:04:14,346] DEBUG - wire >> "}[\r][\n]"
[2016-08-03 14:04:14,347]  INFO - LogMediator Starting inSequence retrieveCustomerHSF = Starting inSequence retrieveCustomerHSF
[2016-08-03 14:04:14,349] DEBUG - wire << "POST /integradorhsf/clientes/ HTTP/1.1[\r][\n]"
[2016-08-03 14:04:14,349] DEBUG - wire << "Content-Type: application/json; charset=UTF-8[\r][\n]"
[2016-08-03 14:04:14,349] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2016-08-03 14:04:14,349] DEBUG - wire << "Host: localhost:8082[\r][\n]"
[2016-08-03 14:04:14,349] DEBUG - wire << "Connection: Keep-Alive[\r][\n]"
[2016-08-03 14:04:14,349] DEBUG - wire << "User-Agent: Synapse-PT-HttpComponents-NIO[\r][\n]"
[2016-08-03 14:04:14,349] DEBUG - wire << "[\r][\n]"
[2016-08-03 14:04:14,349] DEBUG - wire << "64[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << "{[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << ""nomCliente": "SILVA",[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << ""tipoPessoa": "FIS",[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << ""dscEmail": "google@google.com.br"[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << "}[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << "[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << "0[\r][\n]"
[2016-08-03 14:04:14,350] DEBUG - wire << "[\r][\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> "HTTP/1.1 200 OK[\r][\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> "Content-Type: application/json[\r][\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> "Content-Length: 47[\r][\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> "Server: Jetty(6.1.26)[\r][\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> "[\r][\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> "{[\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> ""retorno": "dados cliente",[\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> ""msg": "error"[\n]"
[2016-08-03 14:04:14,356] DEBUG - wire >> "}[\n]"
[2016-08-03 14:04:14,360]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:117c7eb8-c4f2-40a4-b26d-73f64863303a, Direction: response, Starting outSequence retrieveCustomerHSF = Starting outSequence retrieveCustomerHSF, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><retorno>dados cliente</retorno></soapenv:Body></soapenv:Envelope>
[2016-08-03 14:04:14,369] DEBUG - wire << "HTTP/1.1 200 OK[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "Content-Type: application/json; charset=UTF-8[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "Date: Wed, 03 Aug 2016 17:04:14 GMT[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "Transfer-Encoding: chunked[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "1b[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "{"retorno":"dados cliente"}[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "0[\r][\n]"
[2016-08-03 14:04:14,369] DEBUG - wire << "[\r][\n]"

2 个答案:

答案 0 :(得分:1)

理想情况下,这不能返回任何东西。在<send/>中添加<outSequence/>介体可以解决问题。您可以启用有线日志并以其他方式检查。

答案 1 :(得分:0)

正如我猜的,消息流可能无法正确识别json格式。请按如下方式更改顺序,然后尝试:

<outSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="messageType" value="application/json" scope="axis2" type="STRING"></property>
<send/>
</outSequence>

对于复杂的JSON响应,您可以使用:

<outSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="messageType" value="application/json/badgerfish" scope="axis2" type="STRING"></property>
<send/>
</outSequence>