2013-05-31 236 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編寫腳本來執行所需的操作。