2016-11-01 60 views
1

我已经定义在WSO2 ESB一个API和它调用通过recepient列表中的两个内部的API并且被传递JSON响应如下:(样品响应)聚集多个JSON响应

{ 
    "name": "api1", 
    "response": "success", 
    "status": "1" 
} 

{ 
    "name": "api2", 
    "response": "unsuccess", 
    "status": "2" 
} 

我需要通过聚合这两个响应作为单个响应来传递响应。我关于payloadfactory并且能够构建聚合响应。但我需要聚合无论从这些2层的API来的响应,并产生响应为一个单一的JSON对象并且通过包括这两个响应的传递如下

{ 
    "response1": { 
     "name": "api1", 
     "response": "success", 
     "status": "1" 
    }, 
    "response2": { 
     "name": "api2", 
     "response": "unsuccess", 
     "status": "2" 
    } 
} 

因此如何能与WSO2ESB一个完成。我正在使用最新版本的ESB。

回答

0

嗯,这是丰富介体变得方便的地方。请试试看。我没有测试过,因为我现在没有做WSO2相关的东西。但您的反馈热烈欢迎。伪代码是这样的。

<call> 
    <endpoint> 
     <http method="GET" uri-template="http://www.mocky.io/v2/some-ep"/> 
    </endpoint> 
</call> 
<enrich> 
    <source type="body" clone="true"/> 
    <target type="property" property="first-json"/> 
</enrich> 
    <call> 
    <endpoint> 
     <http method="GET" uri-template="http://www.mocky.io/v2/another-ep"/> 
    </endpoint> 
</call> 
<enrich> 
    <source type="property" property="first-json" clone="true"/> 
    <target action="sibling" xpath="//"/> 
</enrich> 
</respond> 
+0

好的。感谢你的回答。我会尝试 –

+0

还有一件事,你的有效载荷结构是错误的。它应该是json中的一个集合,应该像{[{name:Marc,response:resp1,status:...},{...}]} –

+0

我错过了有效负载中的一小部分,并且您的示例json也不正确,因为它没有根元素。顺便谢谢。 { \t “响应”:[{ \t \t “名称”: “马克”, \t \t “响应”: “resp1”, \t \t “状态”: “1” \t},{ \t \t“名 “: ”马克“, \t \t ”回应“: ”resp1“, \t \t ”状态“: ”1“。 \t}]} –