I can convert all JSON payload with the following steps in ESB 4.5.0. These steps include modifying the message builder and message formatting for the application / json content type.
Change the message builder, formatter for JSON; In CARBON_HOME / repository / conf / axis2 / axis2.xml, disable the default message builder and message formatter by commenting out the following lines,
<messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONBuilder"/> <messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONMessageFormatter"/>
Include JSONStreamBuilder and JSONStreamFormatter, uncommenting the following lines,
<messageFormatter contentType="application/json" class="org.apache.axis2.json.JSONStreamFormatter"/> <messageBuilder contentType="application/json" class="org.apache.axis2.json.JSONStreamBuilder"/>
Write a Javascript function to convert and build the new XML payload.
function transformRequest(mc) { var array = mc.getPayloadJSON(); var payload = <games/>; for (i = 0; i < array.length; ++i) { var elem = array[i]; payload.game += <game> <position>{elem.position}</position> <team_id>{elem.team_id}</team_id> <team>{elem.team}</team> <played>{elem.played}</played> <won>{elem.won}</won> <drawn>{elem.drawn}</drawn> <lost>{elem.lost}</lost> <for>{elem["for"]}</for> <against>{elem.against}</against> <difference>{elem.difference}</difference> <points>{elem.points}</points> <info>{elem.info}</info> </game> } mc.setPayloadXML(payload); }
Modify outSequence to perform the conversion on the incoming JSON payload.
<outSequence> <script language="js" key="conf:/repository/esb/scripts/transformrequest.js" function="transformRequest"/> <property name="messageType" value="text/xml" scope="axis2"/> <send/> </outSequence>
source share