I would to publish a SOAP service as REST(json) API . The service operation I want to expose has a xml sequence element in the WSDL/XSD definition:
<xs:complexType name="hellolist">
<xs:sequence>
<xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="hellolistResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
I don't know how to map a JSON array to a xml sequence using PayloadFactory. All the samples I found deal only with simple json and SOAP messages like this sample WSO2 transformation . I would like to transform this json message:
{"hellolist":{"name":["Peter","Mary","Ann","James"]}}
To this soap message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:dum="http://dummyservice2.com/">
<soapenv:Header/>
<soapenv:Body>
<dum:hellolist>
<name>Peter</name>
<name>Mary</name>
<name>Ann</name>
<name>James</name>
</dum:hellolist>
</soapenv:Body>
</soapenv:Envelope>
You can use payload factory mediator to do this. It can be used to transform or replace message content in between the client and the back-end server. In the case of your scenario you can configure a proxy service as below.
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="json_to_xml_factory"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<payloadFactory media-type="xml">
<format>
<dum:hellolist xmlns:dum="http://dummyservice2.com/">
<name xmlns="">$1</name>
<name xmlns="">$2</name>
<name xmlns="">$3</name>
<name xmlns="">$4</name>
</dum:hellolist>
</format>
<args>
<arg evaluator="json" expression="$.hellolist.name[0]"/>
<arg evaluator="json" expression="$.hellolist.name[1]"/>
<arg evaluator="json" expression="$.hellolist.name[2]"/>
<arg evaluator="json" expression="$.hellolist.name[3]"/>
</args>
</payloadFactory>
<log level="full"/>
</inSequence>
<outSequence/>
</target>
<description/>
</proxy>
Please refer below links for more information on this.
https://docs.wso2.com/display/ESB490/PayloadFactory+Mediator http://christinetechtips.blogspot.com/2014/02/payload-factory-mediators-to-work-with.html http://madhukaudantha.blogspot.com/2013/05/wso2-esb-payload-mediator-tutorial.html
If you have a non-static payload (your case), payload-factory-mediator will not be the solution (only for static payload). The best way for your kind of a problem is using xslt mediator + enrich mediator in WSO2 ESB. You can try out this example, https://docs.wso2.com/display/ESB481/Sample+440%3A+Converting+JSON+to+XML+Using+XSLT
Or you can use script mediator in case, as explained in this example. https://docs.wso2.com/display/ESB481/Sample+350%3A+Introduction+to+the+Script+Mediator+Using+JavaScript . Yet not the most preffered way.
I have done your kind of conversions using WSO2 ESB as I described above. But I don't know whether those mediator tools are also available with WSO2 APIM (I couldn't find any example when I googled for your problem).
Try the steps mention below
Steps to Convert a SOAP Test service in SoapUI with assertions into JSON service with assertions
Now you can see all the services in the newly opened project will be in JSON format and all assertions will be available that were in SOAP call previously.
also refer the link which helps to convert the request completely including the assertions
please reply if it is not helpful
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.