2

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>
Community
  • 1
  • 1

2 Answers2

3

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/

  • Hi @Lahiru, In WSO2 EI 6.1.1 how can we achieve this aggregation expression part. as i mentioned earlier comment in this post, that doesn't working. any idea would be greatly appreciated? – Justin May 15 '20 at 06:08
2

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

Nirothipan
  • 314
  • 1
  • 2
  • 14
  • Hi @Nirothipan, $body/*[1] in aggragete expression is not working in WSO2 EI 6.1.1. getting exception like "forceExpand: error parsing data soruce document for element jsonObject". – Justin May 15 '20 at 06:02