As show in the above figure , There is a client that sends a any type of message to the ESB and then to the Back end. and Then Back end sends a message with type other than JSON. And there is a use case user wants to access the incoming payload from the Back end in the Script Mediator. using
This works perfectly when Backend sends messages of type application/json. If Backend sends a message of any type other than application/json , above line of code cannot be used to access the JSON payload inside the script mediator.
i wrote the following custom mediator  to convert the payload into JSON and set it as a property in the message context. So it can be accessed in the script mediator and do what ever you want to do with the payload :).
Instructions are as follows.
How to Use
- Download Jar  and copy it to CARBON_HOME/repository/components/lib.
- Change the Builder and Formatter for application/json in CARBON_HOME/repository/conf/axis2/axis2.xml to
WSO2 ESB 4.7.0
WSO2 ESB 4.8.1
Then in the out sequence use the following synapse config
<outSequence> <class name="org.wso2.carbon.esb.forceful.json.ForcefulJsonConvertor"/> <script language="js"> var json=mc.getProperty("FORCE_BUILT_JSON"); mc.setPayloadJSON(json); </script> <property name="messageType" value="application/json" scope="axis2" type="STRING"/> <send/> </outSequence>
This can be used in the in sequence as well only if the incoming message type is other than application/json. Because if the incoming message type is application/json , getPayloadJSON() can be used to get the json payload in the script mediator. Hope this may be a help .