【问题标题】:WSO2 ESB aggregate with two responeWSO2 ESB 聚合有两个响应
【发布时间】:2018-11-09 17:29:41
【问题描述】:

我已经创建了带有迭代和聚合的 API。但两者的反应没有结合。不时两个响应显示为单一。我将此请求称为 POST 方法,并将 Info 标记作为 AD 发送。 inSequence 部分工作。但是 outSequence 标记两个响应没有合并。请帮我继续。

<?xml version="1.0" encoding="UTF-8"?>
<api context="/Info" name="InfoRequestAPI" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST" protocol="http">
        <inSequence>
            <property expression="$body//Request/OptionInfoRequest/Info" name="OptionInfo" scope="default" type="STRING"/>  

            <script language="js"><![CDATA[var payloadXML = mc.getPayloadXML();
                var xml = '<ItemList>';
                for each (var item in String(mc.getProperty("OptionInfo")).split(',')) {
                    xml +='<item>'+item+'</item>';
                }
                xml +='</ItemList>';
                payloadXML.appendChild(new XML(xml));
                mc.setPayloadXML(payloadXML);
                mc.setProperty("ORIGINAL_PAYLOAD",payloadXML);]]></script>
            <iterate continueParent="true" expression="$body//Request/ItemList/item" id="option_info_request" sequential="true" xmlns:fn="http://www.w3.org/2005/xpath-functions">
                <target>
                    <sequence>
                        <switch source="//item" xmlns:m0="$body">
                            <case regex="A">                                    
                                <send>
                                    <endpoint>
                                        <http format="rest" method="post" uri-template="http://localhost:8280/oneOption"/>
                                    </endpoint>
                                </send>
                            </case>
                            <case regex="D">                                    
                                <send>
                                    <endpoint>
                                        <http format="rest" method="post" uri-template="http://localhost:8280/secondOption"/>
                                    </endpoint>
                                </send>
                            </case>                                
                            <default>
                                <send>
                                    <endpoint key="error_response"/>
                                </send>
                            </default>
                        </switch>
                    </sequence>
                </target>
            </iterate>
        </inSequence>
        <outSequence>
            <property name="ECNCLOSING_ELEMENT" scope="default">
                <wrapper xmlns=""/>
            </property>               
            <aggregate id="option_info_request">
                <completeCondition timeout="10">
                    <messageCount max="-1" min="-1"/>
                </completeCondition>                        
                    <onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="$body/*[1]" enclosingElementProperty="">                       
                    <send/>
                </onComplete>
            </aggregate>                
            <respond/>
        </outSequence>
        <faultSequence/>                
    </resource>
</api>

【问题讨论】:

    标签: wso2 aggregate wso2esb esb


    【解决方案1】:

    为什么enclosingElementProperty=""是空的,这个属性是所有迭代结果的根标签,你需要定义这个属性然后在enclosingElementProperty中使用它,像这样

    <property name="ECNCLOSING_ELEMENT" scope="default">
        <wrapper xmlns=""/>
    </property>
    

    然后

      <onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="$body/*[1]" enclosingElementProperty="ECNCLOSING_ELEMENT"> 
    

    【讨论】:

      【解决方案2】:

      我添加了如下代码。这对我来说很好用。

                  <property name="enclosing_element" scope="default">
                      <Reply/>
                  </property>
      
      
                  <aggregate id="option_info_request">
                      <completeCondition timeout="60">
                          <messageCount max="-1" min="-1"/>
                      </completeCondition>
                      <onComplete enclosingElementProperty="enclosing_element" expression="$env/*[local-name()='Body']/*">                        
                      </onComplete>
                  </aggregate>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-28
        • 2016-05-12
        • 2016-11-22
        • 2015-04-29
        • 1970-01-01
        相关资源
        最近更新 更多