4

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?

Community
  • 1
  • 1
Ivo
  • 1,228
  • 1
  • 15
  • 33

1 Answers1

2

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.

Amila Suriarachchi
  • 1,228
  • 7
  • 5
  • Yes, the JSON I use, however, cannot be converted to XML by the builder and that's why I want to change it before the builder. The JSON object has an array at the root and that's why it cannot be converted to xml, I want to add artificial root at the top so it can be parsed. So this approach can't work in this case? – Ivo Jul 23 '12 at 06:09