我已经创建了具有迭代和聚合功能的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>
答案 0 :(得分:2)
总的来说,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">
答案 1 :(得分:0)
我添加了以下代码。这对我来说很好。
<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>