0

我正在调用 wso2 DSS 服务,它会返回如下数据:

<IdentifierCollection xmlns="http://tempuri.org/">
 <Identifier>
        <One>1</One>
    <Two>2</Two>
    <Three>3</Three>
    </Identifier>
</IdentifierCollection>

要调用 Dss,我的 esb 代码是:

<payloadFactory>
            <format>
               <p:GetIdentifier xmlns:p="http://tempuri.org/">
                  <xs:ID xmlns:xs="http://tempuri.org/">$1</xs:ID>
               </p:GetIdentifier >
            </format>
            <args>
               <arg expression="get-property('ID')"/>
            </args>
         </payloadFactory>
         <send receive="ResponseOfGetIdentifier">
            <endpoint key="IdentifierEP"/>
         </send>

现在在我的 ResponseOfGetIdentifier 序列中,我正在捕获属性中的所有数据

<sequence xmlns="http://ws.apache.org/ns/synapse" name="ResponseOfGetIdentifier">
   <iterate xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org/" preservePayload="true" attachPath="//p:EntriesCollection" expression="//p:EntriesCollection/p:Entries" id="IterateForResponse">
      <target>
<sequence>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org" name="ResponseOne" expression="//p:Identifier/p:one" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org" name="ResponseTwo" expression="//p:Identifier/p:Two" scope="default" type="STRING"/>
<property xmlns:ns="http://org.apache.synapse/xsd" xmlns:p="http://tempuri.org" name="ResponseThree" expression="//p:Identifier/p:Three" scope="default" type="STRING"/>
<payloadFactory>
         <format>
<tns:ProductIdentifier xmlns:tns="http://globalArther.products.com">
<IdentifierProducts>
<Product1>$1</Product1>
<Product2>$2</Product>
<Product3>$3</Product3>
</IdentifierProducts>
</tns:ProductIdentifier>
</format>
<args>
<arg expression="get-property('ResponseOne')"/>
<arg expression="get-property(''ResponseTwo)"/>
<arg expression="get-property('ResponseThree')"/>
</args>
</payloadFactory>
</sequence>
</target>
   </iterate>
</sequence>

由于我的 dss 响应仅包含标识符节点的一次迭代,因此上面的代码正在工作,但是当我的标识符节点计数大于一个时,即

<IdentifierCollection xmlns="http://tempuri.org/">
 <Identifier>
        <One>1</One>
    <Two>2</Two>
    <Three>3</Three>
    </Identifier>
<Identifier>
        <One>a</One>
    <Two>b</Two>
    <Three>c</Three>
    </Identifier>
</IdentifierCollection>

,由于我的有效载荷只能采用一个数据,因此它采用第二次迭代数据并仅向我显示单个结果:

<tns:ProductIdentifier xmlns:tns="http://globalArther.products.com">
    <IdentifierProducts>
    <Product1>a</Product1>
    <Product2>b</Product>
    <Product3>c</Product3>
    </IdentifierProducts>
    </tns:ProductIdentifier>

但我希望我的回应是:

<tns:ProductIdentifier xmlns:tns="http://globalArther.products.com">
        <IdentifierProducts>
        <Product1>1</Product1>
        <Product2>2</Product>
        <Product3>3</Product3>
        </IdentifierProducts>
<IdentifierProducts>
        <Product1>a</Product1>
        <Product2>b</Product>
        <Product3>c</Product3>
        </IdentifierProducts>
</tns:ProductIdentifier>

所以现在我的问题是如何做到这一点,即如何使我的有效负载动态化,即我想在我的有效负载中添加每个迭代。期待您的回答。在此先感谢

4

1 回答 1

1

有效载荷是一种静态的。您需要使用 XSLT 中介来实现这一点。也就是说,您必须编写 XSLT 脚本来制作迭代逻辑。

于 2013-06-06T12:09:31.173 回答