2016-08-02 77 views
0

我在WSO2 Enterprise Service Bus中創建了一個REST API。 的API調用上了SoapUI一個模擬服務,它返回一個JSON有2個節點:WSO2 ESB中的API只返回JSON的第一個節點?

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

ESB應該返回此JSON,但它總是忽略第二個節點(「味精」),並只返回的第一個節點。

我已經改變了位置,這樣的事情,但它並不作品:

{ 
    "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": "[email protected]"[\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": "[email protected]"[\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]" 
+1

請加上'log4j.logger.org.apache.synapse.transport.http.wire = DEBUG'到log4j.properties文件並使用連線日誌更新問題。 – Bee

+0

什麼是您的ESB版本? –

+1

在axis2.xml中爲application/json配置的消息生成器/格式化程序是什麼? –

回答

1

理論上講,該回不了任何東西。在<outSequence/>裏面加入<send/>調解器可以解決問題。您可以啓用電線日誌並進行其他檢查。

+0

我加了以後果。 API響應,但只有JSON的第一個節點。我嘗試使用,我也遇到了同樣的問題。 –

+0

請嘗試啓用評論中提供的Bathiya電線日誌,並將電線日誌作爲編輯粘貼到問題中。 –

+0

對不起。我沒有看到Bhathiya的消息。我要粘貼電線日誌。 –

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>