在WSO2中组合来自iterate mediator的json响应

在WSO2中组合来自iterate mediator的json响应,wso2,wso2esb,Wso2,Wso2esb,为了获得每个令牌和id,我迭代了以下json:{ “答复”:{ “数据”:[{ “令牌”:“12345”, “代码”:“10148117” }, { “令牌”:“123465”, “代码”:“10148118” }] } } 我曾尝试将其汇总,但没有成功: <aggregate id="it1"> <completeCondition> <messageCount min="-1" max="-1" />

为了获得每个令牌和id,我迭代了以下json:
{
“答复”:{
“数据”:[{
“令牌”:“12345”,
“代码”:“10148117”
}, {
“令牌”:“123465”,
“代码”:“10148118”
}]
}
}

我曾尝试将其汇总,但没有成功:

 <aggregate id="it1">
            <completeCondition>
                <messageCount min="-1" max="-1" />
            </completeCondition>
            <onComplete expression="$body/*[1]">
               <log>...<log>
            </onComplete>
        </aggregate>

...
有人能告诉我哪里做错了吗?我怀疑我用错了-xpression=“$body/*[1]”,或者是否有方法将响应中的结果属性组合到json中。另外,聚合应该在迭代中介器的内部或外部,我从两个方面都看到了

编辑:

过了一段时间,我终于用上了:

 <aggregate id="it1">
    <completeCondition>
        <messageCount max="-1" min="-1"/>
    </completeCondition>
    <onComplete expression="//jsonObject/success" xmlns:ns="http://org.apache.synapse/xsd">
        <log level="full">...</log>
    </onComplete>
</aggregate>

...

我不知道这是否是最好的解决方案,但它对我很有效,帮助我从响应中提取所需的值并进行聚合。

当我看到这个问题时,我的第一个想法是您为迭代中介器给出的表达式是否正确。假设您已经包含了您正在迭代的确切json负载,那么表达式应该如下所示:

<iterate expression="//Response/data" id="it1">
    .....
</iterate>

.....
对于第二个问题,聚合中介的表达式是正确的。您必须让聚合中介位于迭代中介之外。我看到的唯一问题是,您没有用于合并单个响应的封闭元素。换句话说,我们需要一个外部数组。要实现此目标,请执行以下操作。(将enclosingElementProperty属性添加到onComplete标记)



后端端点是否用SOAP/xml响应?否,它用json响应。
 <aggregate id="it1">
    <completeCondition>
        <messageCount max="-1" min="-1"/>
    </completeCondition>
    <onComplete expression="//jsonObject/success" xmlns:ns="http://org.apache.synapse/xsd">
        <log level="full">...</log>
    </onComplete>
</aggregate>
<iterate expression="//Response/data" id="it1">
    .....
</iterate>
<property name="Aggregated_Responses" scope="default">
     <jsonObject />
</property>    
<aggregate id="it1">
     <completeCondition>
            <messageCount min="-1" max="-1" />
     </completeCondition>
     <onComplete expression="$body/*[1]" enclosingElementProperty="Aggregated_Responses">
             <log>...<log>
     </onComplete>
</aggregate>