Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSO2 ESB JSON to SOAP

Most of the current docs are with reference to SOAP-to-JSON, I was hoping whether there are any reference material or tutorials when using WSO2 ESB to transform JSON response object to SOAP service. Thanks in advance.

Sample service: http://api.statsfc.com/premier-league/table.json?key=free

like image 476
Mohamed Avatar asked Jan 02 '13 19:01

Mohamed


1 Answers

You can achieve this with a configuration similar to the following; (We must set the "messageType" property to "text/xml" to engage the SOAP message builder when responding back to the client.)

<proxy xmlns="http://ws.apache.org/ns/synapse" name="JSONToSOAPService" transports="https,http">
   <target>
      <outSequence>
         <log level="full"/>
         <property name="messageType" value="text/xml" scope="axis2"/>
         <send/>
      </outSequence>
      <endpoint>
         <address uri="http://api.statsfc.com/premier-league/table.json?key=free"/>
      </endpoint>
   </target>
   <description></description>
</proxy>

But if your JSON response object is exactly same as the one you get from the sample service that you've provided (ie., if it is an array of anonymous objects), the ESB is going to cut down the response to include only the first element (see following SOAP response).

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
    <soapenv:Body>
        <position>1</position>
        <team_id>10260</team_id>
        <team>Manchester United</team>
        <played>21</played>
        <won>17</won>
        <drawn>1</drawn>
        <lost>3</lost>
        <for>54</for>
        <against>28</against>
        <difference>26</difference>
        <points>52</points>
        <info>championsleague</info>
    </soapenv:Body>
</soapenv:Envelope>                    
like image 131
udeshike Avatar answered Nov 07 '22 00:11

udeshike