Method-1
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="count_iterate"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="it_count" value="0" scope="operation"/>
<iterate expression="//symbols/symbol" sequential="true">
<target>
<sequence>
<property name="synapse_it_count" expression="get-property('operation', 'it_count')"/>
<script language="js">var cnt_str = mc.getProperty('synapse_it_count');
var cnt = parseInt(cnt_str);
cnt++;
mc.setProperty('synapse_it_count', cnt.toString());</script>
<property name="it_count" expression="get-property('synapse_it_count')" scope="operation"/>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="//symbol">
<log level="custom">
<property name="number of symbols" expression="get-property('operation','it_count')"/>
</log>
<respond/>
</onComplete>
</aggregate>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<description/>
</proxy>
Note:
1.<property name="counter" scope="default" type="STRING" expression="fn:count($body/ticket/IctAttachments/item)"/>
2.<log>
<property expression="$ctx:counter" name="counter"/>
</log>
Method-2
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="count_iterate"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="https,http">
<target>
<inSequence>
<property name="it_count" scope="operation" value="0"/>
<iterate expression="//symbols/symbol" sequential="true">
<target>
<sequence>
<property expression="number(get-property('operation','it_count') +1)"
name="it_count"
scope="operation"/>
<aggregate>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete expression="//symbol">
<log level="custom">
<property expression="get-property('operation','it_count')"
name="number of symbols"/>
</log>
<respond/>
</onComplete>
</aggregate>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<description/>
</proxy>
Input:
<symbols>
<symbol>WSO2</symbol>
<symbol>MSFT</symbol>
<symbol>IBM</symbol>
<symbol>ADBE</symbol>
<symbol>AAPL</symbol>
<symbol>ORCL</symbol>
<symbol>RHT</symbol>
<symbol>FB</symbol>
<symbol>TWTR</symbol>
<symbol>LNKD</symbol>
</symbols>
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="count_iterate"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="it_count" value="0" scope="operation"/>
<iterate expression="//symbols/symbol" sequential="true">
<target>
<sequence>
<property name="synapse_it_count" expression="get-property('operation', 'it_count')"/>
<script language="js">var cnt_str = mc.getProperty('synapse_it_count');
var cnt = parseInt(cnt_str);
cnt++;
mc.setProperty('synapse_it_count', cnt.toString());</script>
<property name="it_count" expression="get-property('synapse_it_count')" scope="operation"/>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="//symbol">
<log level="custom">
<property name="number of symbols" expression="get-property('operation','it_count')"/>
</log>
<respond/>
</onComplete>
</aggregate>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<description/>
</proxy>
Note:
1.<property name="counter" scope="default" type="STRING" expression="fn:count($body/ticket/IctAttachments/item)"/>
2.<log>
<property expression="$ctx:counter" name="counter"/>
</log>
Method-2
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="count_iterate"
startOnLoad="true"
statistics="disable"
trace="disable"
transports="https,http">
<target>
<inSequence>
<property name="it_count" scope="operation" value="0"/>
<iterate expression="//symbols/symbol" sequential="true">
<target>
<sequence>
<property expression="number(get-property('operation','it_count') +1)"
name="it_count"
scope="operation"/>
<aggregate>
<completeCondition>
<messageCount max="-1" min="-1"/>
</completeCondition>
<onComplete expression="//symbol">
<log level="custom">
<property expression="get-property('operation','it_count')"
name="number of symbols"/>
</log>
<respond/>
</onComplete>
</aggregate>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<description/>
</proxy>
Input:
<symbols>
<symbol>WSO2</symbol>
<symbol>MSFT</symbol>
<symbol>IBM</symbol>
<symbol>ADBE</symbol>
<symbol>AAPL</symbol>
<symbol>ORCL</symbol>
<symbol>RHT</symbol>
<symbol>FB</symbol>
<symbol>TWTR</symbol>
<symbol>LNKD</symbol>
</symbols>
No comments:
Post a Comment