I have a REST service that I want to use through wso2 ESB. The service returns a JSON object. I wish however to modify the JSON before it enters the ESB and gets processed.

I've managed to deploy a custom class mediator but I don't know how can I process the message body with it (the JSON object). Is this the right way to do this?

My service configuration looks like this at the moment:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="ListRm" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <outSequence>
         <class name="org.mediator.MyMediator" />
         <send />
         <drop />
      </outSequence>
      <endpoint>
         <address uri="http://xx.xx.xxx.xx:8080/alfresco/s/slingshot/datalists/lists/site/rm/documentLibrary" />
      </endpoint>
   </target>
</proxy>

Also is there some other way to modify the message body before it enters the ESB?

有帮助吗?

解决方案

at the synapse mediation engine level you can not access the json message. At the JSON builder level it converts the json message to an xml message. So you need to access the xml element and do your modifications there.

messageContext.getEnvelope().getBody().getFirstElement();

you can get the xml element as given above.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top