简体   繁体   English

WSO2 ESB:聚合来自多个api调用的JSON响应

[英]WSO2 ESB: Aggregating JSON responses from multiple api calls

I am using WSO2 ESB mediators to try and to create an API which paginates a particular Rest API. 我正在使用WSO2 ESB介体尝试创建一个分页特定Rest API的API。 I am using recursion with the sequence mediator to make calls to a dynamically changing endpoint until all data has been collected. 我在序列中介器上使用递归来调用动态变化的端点,直到收集完所有数据为止。 Unfortunately, I cannot figure out how to aggregate all the responses into one JSON before sending. 不幸的是,我无法弄清楚如何在发送之前将所有响应聚合成一个JSON。

Any help would be appreciated. 任何帮助,将不胜感激。

This is the current code: 这是当前的代码:

<api context="/axceleratePaginated" name="axceleratePaginated">
    <resource methods="GET" protocol="http" url-mapping="/courses">
        <inSequence>
            <property name="uri.var.resource" value="courses"/>
            <property name="uri.var.offset" value="0"/>
            <property name="uri.var.displayLength" value="99"/>
            <property name="JSONContinue" value="true"/>
            <sequence key="paginationSequence"/>
            <send/>
        </inSequence>
        <outSequence>
            <!-- aggregate here? -->
            <send/>
        </outSequence>
    </resource>
</api>
...
<sequence name="paginationSequence" trace="enable">
    <header name="apitoken" scope="transport" value="***********"/>
    <header name="wstoken" scope="transport" value="************"/>
    <call>
        <endpoint>
            <http method="GET" trace="enable" uri-template="https://admin.axcelerate.com.au/api/{uri.var.resource}?displayLength={uri.var.displayLength}&amp;offset={uri.var.offset}"/>
        </endpoint>
    </call>
    <property expression="json-eval($.)" name="JSONPayload"/>
    <filter regex="true" source="get-property('JSONContinue')">
        <then>
            <script language="js">
                <![CDATA[
                    java.lang.Thread.sleep(200);
                    var offset = parseInt(mc.getProperty('uri.var.offset'));
                    offset += 100;
                    var pl_string = mc.getProperty('JSONPayload');
                    var JSONPayloadLength = pl_string.length();
                    if (JSONPayloadLength === 3){
                        mc.setProperty('JSONContinue','false');
                    }
                    offset = offset.toString();
                    mc.setProperty('uri.var.offset',offset);
                ]]>
            </script>
            <sequence key="paginationSequence"/>
        </then>
    </filter>
</sequence>

You can use the Loopback mediator [1] to send messages from the in flow (request path) to the out flow (response path). 您可以使用Loopback介体[1]将消息从流(请求路径)发送到out流(响应路径)。

[1] https://docs.wso2.com/display/ESB490/Loopback+Mediator [1] https://docs.wso2.com/display/ESB490/Loopback+Mediator

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

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