Exposing a SOAP service as a Managed REST API

Shenavi de Mel
Oct 30, 2017 · 7 min read

Introduction

Use Case

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://ws.cdyne.com/PhoneVerify/query">
<soapenv:Header/>
<soapenv:Body>
<quer:CheckPhoneNumber>
<!--Optional:-->
<quer:PhoneNumber>1223334477888</quer:PhoneNumber>
<!--Optional:-->
<quer:LicenseKey>0</quer:LicenseKey>
</quer:CheckPhoneNumber>
</soapenv:Body>
</soapenv:Envelope>
SOAPAction: "http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber"

Tutorial


<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="PhoneVerifyInSequence" >
<!-- This is the SOAP action which the backend SOAP operation expects, we set it in a header mediator --><header description="SOAPAction" name="SOAPAction" scope="transport" value="http://ws.cdyne.com/PhoneVerify/query/CheckPhoneNumber"/><!-- We are storing the input values which the end users input for these values into these two properties --><property name="uri.var.phoneNumber" expression="$url:PhoneNumber"/>
<property name="uri.var.licenseKey" expression="$url:LicenseKey"/>
<!-- Since we do not want the URL pattern we mentioned to be sent to the backend we need to add the below property to remove it --><property name="REST_URL_POSTFIX" scope="axis2" action="remove"/><!-- Now we need to create the actual payload which the backend requires. For that we use the payload factory mediator --><payloadFactory description="transform" media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/" xmlns:quer="http://ws.cdyne.com/PhoneVerify/query">
<soapenv:Header/>
<soapenv:Body>
<quer:CheckPhoneNumber>
<quer:PhoneNumber>$1</quer:PhoneNumber>
<quer:LicenseKey>$2</quer:LicenseKey>
</quer:CheckPhoneNumber></soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg expression="get-property(‘uri.var.phoneNumber’)"/>
<arg expression="get-property(‘uri.var.licenseKey’)"/>
</args>
</payloadFactory>
<!-- Here we are setting the content type which the web service expects --><property description="messageProperty" name="messageType" scope="axis2" type="STRING" value="application/soap+xml"/>
</sequence>
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="xml_to_json_out_message" >
<!-- Transforms the response to a JSON --><property description="message" name="messageType" scope="axis2"
type="STRING" value="application/json"/>
</sequence>

How does this work?

Contact us

References

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade