[英]Use of Iterate Mediator in wso2 ESB
I have my input request as: 我的输入要求为:
<body>
<p:UpdateID xmlns:p="http://tempuri.org">
<!--Exactly 1 occurrence-->
<xs:newid xmlns:xs="http://tempuri.org">NewID</xs:newid>
<!--1 or more occurrences-->
<xs:oldid xmlns:xs="http://tempuri.org">OldID_001</xs:oldid>
<xs:oldid xmlns:xs="http://tempuri.org">OldID_002</xs:oldid>
</p:UpdateID>
</body>
I have written a proxy service which i not working as: 我已经写了一个代理服务,但我不能这样工作:
<proxy xmlns="http://ws.apache.org/ns/synapse" name="UpdateID" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<iterate xmlns:xs="http://tempuri.org" id="Iterate1" expression="count(//xs:oldid)">
<target>
<sequence>
<property name="newid" expression="//xs:newid" scope="default" type="STRING"/>
<property name="oldid" expression="//xs:oldid" scope="default" type="STRING"/>
<payloadFactory>
<format>
<p:UpdateID xmlns:p="http://tempuri.org">
<xs:newid>$1</xs:newid>
<xs:oldid>$2</xs:oldid>
</p:UpdateID>
</format>
<args>
<arg expression="get-property('newid')"/>
<arg expression="get-property('oldid')"/>
</args>
</payloadFactory>
<send>
<endpoint key="UpdateEP"/>
</send>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<publishWSDL uri="http://xyz:9764/services/Update_DataService?wsdl"/>
<description></description>
</proxy>
Now my question is how can i get the count of oldid so that i can iterate from 0 to count of oldid ,Something like for loop. 现在我的问题是如何获取oldid的计数,以便可以从0迭代到oldid的计数 ,有点像for循环。 And second how can i assign oldid value to the payload one by one . 其次,我如何才能将oldid值一一分配给有效负载 。 Please Help. 请帮忙。 Thanks in advance 提前致谢
You can change the iterate expression to expression="//xs:oldid" which will iterate to number of available oldid elements. 您可以将迭代表达式更改为expression =“ // xs:oldid”,这将迭代到可用oldid元素的数量。 Then you can take assignment of the newid value, out of the iterator, since there will be only one newid element. 然后,您将可以从迭代器中分配newid值,因为将只有一个newid元素。 I have update your proxy configuration with those changes. 我已经通过这些更改更新了您的代理配置。
<proxy xmlns="http://ws.apache.org/ns/synapse" name="UpdateID" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<inSequence>
<property name="newid" expression="//xs:newid" scope="default" type="STRING" xmlns:xs="http://tempuri.org"/>
<iterate xmlns:xs="http://tempuri.org" id="Iterate1" expression="//xs:oldid">
<target>
<sequence>
<property name="oldid" expression="//xs:oldid" scope="default" type="STRING"/>
<payloadFactory>
<format>
<p:UpdateID xmlns:p="http://tempuri.org">
<xs:newid>$1</xs:newid>
<xs:oldid>$2</xs:oldid>
</p:UpdateID>
</format>
<args>
<arg expression="get-property('newid')"/>
<arg expression="get-property('oldid')"/>
</args>
</payloadFactory>
<send>
<endpoint key="UpdateEP"/>
</send>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<publishWSDL uri="http://xyz:9764/services/Update_DataService?wsdl"/>
<description></description>
</proxy>
For this scenario, consider using the Script mediator instead. 对于这种情况,请考虑改为使用脚本介体 。 It allows you to write a script in JavaScript or Python to perform the operations you want. 它允许您使用JavaScript或Python编写脚本来执行所需的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.