2
votes

I'm trying to call two endpoints with clone and gather their information to send with aggregate, I must use it with scatter-gather mediator. Each endpoint returns a string in json. But I keep having a "Expecting an implementation of SOAP Envelope as the parent" error. My last attempt is below. What should I use in onComplete expression to make this work?

<resource methods="GET" uri-template="/allInfo">
        <inSequence>
            <log description="Get All Restaurants Info" level="custom" separator=",">
                <property name="message" value="&quot;All information of restaurants&quot;"/>
            </log>
            <clone description="All Info" id="ScatterGatherProxy">
                <target>
                    <endpoint key="RestaurantLocalsEP"/>
                </target>
                <target>
                    <endpoint key="RestaurantNamesEP"/>
                </target>
            </clone>
        </inSequence>
        <outSequence>
            <aggregate id="ScatterGatherProxy">
                <completeCondition>
                    <messageCount max="-1" min="-1"/>
                </completeCondition>
                <onComplete expression="fn:concat('//*')">
                    <send/>
                </onComplete>
            </aggregate>
        </outSequence>
        <faultSequence/>
    </resource>
2
Could you please provide RestaurantLocalsEP and RestaurantNamesEP endpoints definitions? Are they HTTP endpoints? - Maxim Fazyloff

2 Answers

3
votes

Aggregate mediator contains native JSON support from the latest release (6.5.0)(will be released soon) Also, JSON support available for EI 6.1.1 and 6.4.0 via WUM updates.

You can use the following sample configuration

<api xmlns="http://ws.apache.org/ns/synapse" name="aggregate"
context="/testAgg">    <resource methods="POST GET">
       <inSequence>
          <log level="custom" separator=",">
             <property name="message" value="&quot;All information of restaurants&quot;"/>
          </log>
          <clone id="ScatterGatherProxy">
             <target>
                <endpoint name="Cape">
                   <address uri="http://www.mocky.io/v2/5befbf782f000067007a0be4" format="get"/>
                </endpoint>
             </target>
             <target>
                <endpoint name="KSC">
                   <address uri="http://www.mocky.io/v2/5befbfd22f00009a007a0be5" format="get"/>
                </endpoint>
             </target>
          </clone>
       </inSequence>
       <outSequence>
          <aggregate id="ScatterGatherProxy">
             <completeCondition>
                <messageCount min="-1" max="-1"/>
             </completeCondition>
             <onComplete expression="json-eval($)">
                <send/>
             </onComplete>
          </aggregate>
       </outSequence>    </resource> </api>

You can read more info in https://lahirumadushankablog.wordpress.com/2018/11/17/aggregating-json-payloads-in-wso2-ei/

2
votes

You need to add an enclosingElementProperty tag to gather all the outputs into one in on complete condition.

For example you can try like the following

<property name="Aggregated_Responses" scope="default">
    <jsonObject/>
</property>
<aggregate id="NIRO">
<completeCondition>
    <messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:ns="http://org.apache.synapse/xsd" expression="$body/*[1]"
            enclosingElementProperty="Aggregated_Responses">
    <send/>
</onComplete>
</aggregate>

Thanks