Adam Adam - 4 months ago 63
JSON Question

WSO2 esb SOAP to REST conversion issue

I need to convert a soap API into rest via wso2 esb. I have created an API an in that I'm getting the expected response in SOAP. But to convert that soap response into JSON with the out sequence.

When I try to convert the soap response into JSON by using axis2 property mediator it only converts a part of my response. Can you please guide me how to do that in a proper way.

This is my actual soap response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ns1:queryInboxToneResponse xmlns:ns1="http://usertonemanage.ivas.huawei.com" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">...</ns1:queryInboxToneResponse>

<multiRef xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://response.usertonemanage.ivas.huawei.com" id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:QueryInboxToneResp">...</multiRef>

<multiRef xmlns:ns4="http://info.ivas.huawei.com" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns4:ToneInfo">...</multiRef>
</soapenv:Body>
</soapenv:Envelope>


In the response it only converts the first part of the soap response. why ESB ignores the rest of tags in the same level. ("multiRef").

This is my out sequence

<outSequence xmlns="http://ws.apache.org/ns/synapse">
<property name="messageType" value="application/json" scope="axis2" type="STRING"></property>
<send></send>
</outSequence>


This is the response which I got.

{"queryInboxToneResponse":{"@encodingStyle":"http://schemas.xmlsoap.org/soap/encoding/","queryInboxToneReturn":{"@href":"#id0"}}}

Answer

Finally I found the solution for the issue. In the normal case we use

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

But this axis2 property cannot convert the complex soap response into json such as with xsi. For that need to use the following axis2 property. Then it converts the entire soap response into Json as we expected.

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

This is my full outsequence.

<outSequence xmlns="http://ws.apache.org/ns/synapse">
   <property name="messageType" value="application/json/badgerfish" scope="axis2" type="STRING"></property>
   <send></send>
</outSequence>