Anushka Ekanayake
Anushka Ekanayake

Reputation: 987

How to convert text/xml response into application/json wso2 EI

I have a soap service and I need to expose this service as a rest api in Wso2 EI, content type is text/xml, I tried with

<property name="messageType" value="application/json" scope="axis2"/>

in the outsequence, but it doesnt convert my response into a json. Can you please assist me on how to do it.

I tried this,

    <resource methods="POST">
      <inSequence>
         <send>
            <endpoint>
               <address uri="http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2"/>
         <send/>
      </outSequence>
   </resource>

Upvotes: 2

Views: 1991

Answers (2)

RandimaS
RandimaS

Reputation: 19

Reason for this is that WSO2 EI or ESB is developed in a manner where it responds to a SOAP request with a SOAP response by default. When you invoke the PROXY or API with SOAPAction and Content-Type: text/xml, EI understands this as a SOAP request and it'll respond with a SOAP response.

So if the client request is in SOAP-1.1 EI responds with a SOAP-1.1 response or if the client request is in SOAP-1.2 EI responds with a SOAP-1.2.

To bypass this behaviour they have provided an additional property as below.

<property name="IsClientDoingREST" scope="default" type="BOOLEAN" value="true"/>

So, before responding the client, properties should be set as below to get the expected behaviour of responding with a JSON.

<property name="IsClientDoingREST" scope="default" type="BOOLEAN" value="true"/>
<property name="messageType" scope="axis2" value="application/json"/>

This approach will help you to get the JSON response out of a SOAP request.

Upvotes: 2

Arunan
Arunan

Reputation: 3426

It should work perfectly. A sample REST API configuration given below.

<api xmlns="http://ws.apache.org/ns/synapse" name="CheckREST" context="/samplerest">
   <resource methods="GET">
      <inSequence>
         <send>
            <endpoint>
               <http uri-template="http://localhost:8280/services/sampleSOAPproxy"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <property name="messageType" value="application/json" scope="axis2" type="STRING"/>
         <send/>
      </outSequence>
   </resource>
</api>

If not working, please mention the EI version you are using.

Upvotes: 1

Related Questions