Daniel Minnaar Daniel Minnaar - 3 months ago 33
reST (reStructuredText) Question

WSO2 ESB - Error parsing JSON when using the clone mediator with a REST endpoint

I have two REST services that return some simple JSON. I'm using the clone mediator to call each service and then return the aggregated message to the client.

The problem is that everytime I call the API, I get the following error on the ESB output:

ERROR - OMSourcedElementImpl Could not get parser from data source for element jsonObject


I've tested the same REST service individually, without the clone mediator, and it works without a problem.

Here is the API sequence:

<api xmlns="http://ws.apache.org/ns/synapse" name="PolicyQuery" context="/policy/query">
<resource methods="POST">
<inSequence>
<property name="ROOT" scope="default">
<root:rootelement xmlns:root="www.wso2esb.com"/>
</property>
<log level="full"/>
<clone continueParent="true" id="test" sequential="true">
<target>
<sequence>
<send>
<endpoint>
<address uri="http://ip.jsontest.com/" format="rest"/>
</endpoint>
</send>
</sequence>
</target>
<target>
<sequence>
<send>
<endpoint>
<address uri="http://ip.jsontest.com/" format="rest"/>
</endpoint>
</send>
</sequence>
</target>
</clone>
</inSequence>
<outSequence>
<log level="full"/>
<aggregate>
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete expression="//return" enclosingElementProperty="ROOT">
<property name="messageType" value="application/json" scope="axis2" type="STRING"/>
<send/>
</onComplete>
</aggregate>
</outSequence>
</resource>
</api>


Am I doing anything wrong? I'm using WSO2 5.0.0 (I've also tested with 4.9.0 and I get the same problem).

The request payload I'm sending is:

{
IdNumber : "8008185315088",
LastName : null
}

Answer

This worked fine for me after updating out sequence like this. Can you try this?

  <outSequence>
     <log level="full"/>
     <aggregate>
        <completeCondition>
           <messageCount min="2" max="2"/>
        </completeCondition>
        <onComplete expression="//ip" enclosingElementProperty="ROOT">
           <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
           <send/>
        </onComplete>
     </aggregate>
  </outSequence>

Note: The error you're getting can occur if the json you get is in a wrong format. But with this sample, I don't see such an issue.