Reputation: 21
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=""All information of restaurants""/>
</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>
Upvotes: 2
Views: 236
Reputation: 314
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
Upvotes: 2
Reputation: 254
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=""All information of restaurants""/>
</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/
Upvotes: 3