在wso2响应流程中,Foreach在AggregateMediator的范围内无法正常工作

时间:2017-07-11 09:47:26

标签: wso2

Foreach在响应流程中的AggregateMediator范围内无法正常工作

输入请求:

[
    {
        "name" : "Home"
    },
    {
        "name" : "Car"
    },
    {
        "name" : "Mobile"
    }
]

我正在使用iterate,将上面数组的每个元素作为请求发送到传递服务(在我的实际项目中,这不是通过。为了更好地理解问题,我保持这样)。

传递服务的响应由AggregateMediator聚合在一个soap xml中。

以下是AggregateMediator的回复

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <Information>
            <jsonObject>
                <name>Mobile</name>
            </jsonObject>
            <jsonObject>
                <name>Car</name>
            </jsonObject>
            <jsonObject>
                <name>Home</name>
            </jsonObject>
        </Information>
    </soapenv:Body>
</soapenv:Envelope>

使用foreach根据响应中的某些参数修改每个响应。 但Foreach在响应流程中的聚合器范围内无法正常工作。它的反应很奇怪。

For-each response:

[2017-07-11 14:07:44,696]  INFO - LogMediator msg4 = "Inside Foreach"
[2017-07-11 14:07:44,697]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:3e1fd827-12ab-413c-824d-c9daf7b6df7c, Direction: response, Envelope: <?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <jsonObject>
            <name>Home</name>
        </jsonObject>
    </soapenv:Body>
</soapenv:Envelope>

[2017-07-11 14:07:44,697]  INFO - LogMediator msg4 = "Inside Foreach"
[2017-07-11 14:07:44,697]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:3e1fd827-12ab-413c-824d-c9daf7b6df7c, Direction: response, Payload: {"name":"Home"}

[2017-07-11 14:07:44,697]  INFO - LogMediator msg4 = "Inside Foreach"
[2017-07-11 14:07:44,698]  INFO - LogMediator To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:3e1fd827-12ab-413c-824d-c9daf7b6df7c, Direction: response, Payload: {"name":"Home"}

--------------------------------------------------------------------------------
The second and third iterate of foreach should have been like below :

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <jsonObject>
            <name>Mobile</name>
        </jsonObject>
    </soapenv:Body>
</soapenv:Envelope>

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <jsonObject>
            <name>Car</name>
        </jsonObject>
    </soapenv:Body>
</soapenv:Envelope>

Instead of :

 Payload: {"name":"Home"}
 Payload: {"name":"Home"}

请参阅以下流程xml&#39>。

forEachTest.xml:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/foreschTest" name="foreachTest" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST GET" uri-template="/hi">
        <inSequence>
            <log level="full"/>
            <log level="custom">
                <property expression="//jsonArray" name="message"/>
            </log>
            <iterate expression="//jsonArray/jsonElement" id="1">
                <target>
                    <sequence>
                        <log level="custom">
                            <property name="msg2" value="&quot;Inside Foreach&quot;"/>
                        </log>
                        <log level="full"/>
                        <send>
                            <endpoint key="modifyAgrRespEP"/>
                        </send>
                    </sequence>
                </target>
            </iterate>
        </inSequence>
        <outSequence>
            <property name="info" scope="default">
                <Information xmlns=""/>
            </property>
            <aggregate id="1">
                <completeCondition>
                    <messageCount max="-1" min="-1"/>
                </completeCondition>
                <onComplete enclosingElementProperty="info" expression="//jsonObject">
                    <log level="custom">
                        <property name="msg3" value="&quot;Inside Aggr&quot;"/>
                    </log>
                    <log level="full"/>
                    <foreach expression="//Information/jsonObject">
                        <sequence>
                            <log level="custom">
                                <property name="msg4" value="&quot;Inside Foreach&quot;"/>
                            </log>
                            <log level="full"/>
                        </sequence>
                    </foreach>
                </onComplete>
            </aggregate>
        </outSequence>
        <faultSequence/>
    </resource>
</api>

modifyAgrRes(Passthrough flow):

<?xml version="1.0" encoding="UTF-8"?>
<api context="/mod" name="modifyAgrRes" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST GET" uri-template="/aggr">
        <inSequence>
            <log level="custom">
                <property name="message" value="&quot;Inside Modify Service *************************&quot;"/>
            </log>
            <log level="custom">
                <property expression="//jsonObject" name="location"/>
            </log>
            <respond/>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
        <faultSequence/>
    </resource>
</api>

0 个答案:

没有答案