简体   繁体   English

WSO2 ESB调用参数化参数化端点循环

[英]WSO2 ESB calling parameterized endpoint Looping on Parameters

In my usecase i have to chain two service calls. 在我的用例中,我必须链接两个服务调用。 In particular: 特别是:

1) The first call returns an xml listing several IDs 1)第一个调用返回一个列出多个ID的xml

2) i have to iterate through the returned ID list and to make an ID parameterized service call for each id-item. 2)我必须遍历返回的ID列表并为每个id-item进行ID参数化服务调用。

3) Finally i have to collect a whole response made up of each single ID-service-response. 3)最后,我必须收集由每个ID-service-response组成的完整响应。

Suppose the first service call returns a response like this one: 假设第一个服务调用返回如下响应:

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

The second step is to perform a series of calling to parameterized endpoint like this: 第二步是执行一系列调用参数化端点,如下所示:

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

each call of which returns an xml response like this: 每个调用返回一个xml响应,如下所示:

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

I have to collect a whole response like this one: 我必须收集像这样的完整回复:

<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? 我能怎么做? Could you give me some example? 你能举个例子吗? Thanks 谢谢

You need to use iterate mediator and aggregate mediator in combination. 您需要组合使用迭代介体和聚合介体。 Here is a sample code, but you may need to do some modification in order 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 on related sample here . 这里有相关示例的完整文档。 Find how you can parameterize you url here . 在这里找到你如何参数化你的网址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM