Reputation: 832
I have create API with iterate and aggregate. But both response not combined. time to time both response showing as single. I have call this request as POST method and Info tag send as AD. inSequence section working. but outSequence tag both response not combined. Please help me to continue this.
<?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>
Upvotes: 1
Views: 473
Reputation: 832
I have added like following code. This is working fine for me.
<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>
Upvotes: 0
Reputation: 495
In aggregate why is enclosingElementProperty=""
empty, This property acts a a root tag for all the iterated result, you need to define the property and then use it in enclosingElementProperty
, something like this
<property name="ECNCLOSING_ELEMENT" scope="default">
<wrapper xmlns=""/>
</property>
and then
<onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="$body/*[1]" enclosingElementProperty="ECNCLOSING_ELEMENT">
Upvotes: 2