WSO2 ESB calling the parameterized endpoint. Quoting by parameters

In my usecase, I have to connect two service calls. In particular:

1) First call returns xml listing multiple ids

2) I need to iterate over the list of returned ids and make an identity call to the service with ID parameters for each id element.

3) Finally, I need to collect the entire response, made up of each individual service ID response.

Suppose the first call to the service returns a response like this:

<result>     
    <Link>
        <Id>93451</Id>
    </Link>
    <Link>
        <Id>93450</Id>
    </Link>
    ...

      

The second step is to make a series of calls to the parameterized endpoint like this:

http://myEndpoint/entry/eutils/efetch.fcgi?db=pubmed&rettype=abstract&retmode=xml&id=<ID>

      

each call which returns an xml response like this:

<response>
    <field1>value1</field1>
    <field2>value2</field2>
    <field3>value3</field3>
<response>

      

I need to put together a whole answer like this:

<finalResponse>
    <response>
        <field1>value1</field1>
        <field2>value2</field2>
        <field3>value3</field3>
    <response>
    <response>
        <field1>value1</field1>
        <field2>value2</field2>
        <field3>value3</field3>
    <response>
    <response>
        <field1>value1</field1>
        <field2>value2</field2>
        <field3>value3</field3>
    <response>
</finalResponse>

      

How can i do this? Could you give me an example? Thanks to

+3


source to share


1 answer


You need to use an iteration pick and an aggregate pick in combination. Here is some sample code, but you might need to make some changes to make it work for your requirements.

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="SampleProxy">
        <target>
            <inSequence>
                <iterate expression="//result/link/id" preservePayload="true"
                         attachPath="//link">
                    <target>
                        <property name="uri.var.servicepath" expression="//link/id/text()"/>
                        <sequence>
                            <send>
                                <endpoint key="MyEndpoint"/>
                            </send>
                        </sequence>
                    </target>
                </iterate>
            </inSequence>
            <outSequence>
                <property name="FinalResponse" scope="default">
                    <finalResponse />
                </property>
                <aggregate>
                    <onComplete expression="//response"
                                enclosingElementProperty="FinalResponse">
                        <send/>
                    </onComplete>
                </aggregate>
            </outSequence>
        </target>
    </proxy>

    <endpoint xmlns="http://ws.apache.org/ns/synapse" name="MyEndpoint">
        <http uri-template="http://myEndpoint/entry/eutils/efetch.fcgi?db=pubmed&amp;rettype=abstract&amp;retmode=xml&amp;id={ID}" method="GET">
        </http>
    </endpoint>
</definitions>

      



Full documentation for the relevant sample is here . Find how you can parameterize the url here .

+3


source







All Articles