Вопрос

I am invoking a wso2 DSS service which returns me data like:

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

To invoke Dss my esb code is:

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

Now in my ResponseOfGetIdentifier Sequence i am capturing all data in properties

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

Since my dss response contains only one iteration of Identifier node hence above code is working but when my identifier node count is more than one i.e

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

, since my payload can take only one data it takes the second iteration data and shows me only single result as:

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

But i want my response as :

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

So now my question is how can i do that i.e how can i make my payload dynamic i.e. i want to add every iteration in my payload. Looking forward to your answers.Thanks in advance

Это было полезно?

Решение

Payload is kind of static. You need to use XSLT mediator to achieve this .That is, you have to write XSLT script to make the iteration logic.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top