2013-05-31 174 views
0

使用迭代调解员的我有我的输入请求为:在WSO2 ESB

<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> 

我写,我不工作的代理服务为:

<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> 

现在我的问题是怎么能我得到了oldid的数量,以便我可以从0迭代到oldid的计数,类似for循环。 第二,我如何分配oldid值到负载一个接一个。 请帮助。在此先感谢

回答

4

您可以将迭代表达式更改为expression =“// xs:oldid”,它将迭代到可用的oldid元素的数量。然后,您可以从迭代器中分配newid值,因为只会有一个newid元素。我已经使用这些更改更新了您的代理配置。

<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> 
2

对于此方案,请考虑使用Script mediator来代替。它允许您使用JavaScript或Python编写脚本来执行所需的操作。