Thursday, August 20, 2015

SOAP webservice as a REST API - WSO2 API Manager (1.9) -2

1. I'm going to use the weather service which is available in public. (

2. This SOAP service has a operation called "GetCitiesByCountry". You can get the following results when It access directly from the SOAPUI.

3. Now I'm going to create API in WSO2 API Manager to expose this service operation as a REST operation.

Eg: Expose the  GetCitiesByCountry as GET method as bellow.
4. We want to write a mediation extension to read the "country" from request and construct the SOAP payload which is  expect by back end service (I'm going to save this file as JSONtoSOAP.xml). This file shroud upload to /_system/governance/apimgt/customsequences/in in registry.
<sequence xmlns="" name="admin--weather:vv1.0.0--In">  
 <property name="country" expression="$url:country"></property>
   <payloadFactory media-type="xml">  
               <soapenv:Envelope xmlns:soapenv=""  
               <arg xmlns:m0="http://services.samples/xsd" evaluator="xml" 

5. We want another mediation extension file to convert the SOAP response to JSON.(I'm going to save this file as SOAPtoJSON.xml). This file should upload to /_system/governance/apimgt/customsequences/out in registry.
<sequence xmlns="" name="admin--weather:vv1.0.0--Out">
   <property name="messageType" value="application/json" scope="axis2"/>

6.  Create an API as bellow. (Make sure to add new query parameter called country for GetCitiesByCountry resource)

7. Go to the implement wizard  and select the end point type as "Address Endpoint". Then define the endpoint as

8.  Click on the "Advance Options" button and select the "Format" as SOAP 1.2.

9. Go to the manage wizard and select the custom mediation form the "Message Mediation Policies".

10. Click on "save & publish" button to publish this API to store.

11. Login to the store ,  subscribe that API  to an application and generate a token.

12. Use the following Curl command to invoke the  GetCitiesByCountry operation.

curl  -k -H "Authorization :Bearer 99215d98fa10ce6f2d83cd11ba9828" -H "Content-Type:application/json"   https://localhost:8243/weather/v1.0.0/GetCitiesByCountry?country=Romania

13. You can also use the SOAPUI to invoke that API. (Make sure to define the  Authorization header)

Related posts: