- GetCitiesByCountry
- GetWeather
2. Create an API in ESB to invoke the above operations using following REST operations (ESB start with port offset as 1).
http://localhost:8281/weatheresb/GetCitiesByCountry?CountryName=Romania
http://localhost:8281/weatheresb/GetCitiesByCountry?CountryName=Romania&CityName=Timisoara
Save this file as WeatherAPIESB.xml in <ESB_Home>\repository\deployment\server\synapse-configs\default\api)
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse"
name="WeatherAPIESB"
context="/weatheresb">
<resource methods="GET" url-mapping="/GetCitiesByCountry">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetCitiesByCountry><web:CountryName>$1</web:CountryName>
</web:GetCitiesByCountry>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg xmlns:m0="http://services.samples/xsd"
evaluator="xml"
expression="get-property('query.param.CountryName')"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="http://www.webservicex.com/globalweather.asmx" format="soap12"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</resource>
<resource methods="GET" url-mapping="/GetWeather">
<inSequence>
<payloadFactory media-type="xml">
<format>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://www.webserviceX.NET">
<soapenv:Header/>
<soapenv:Body>
<web:GetWeather><web:CityName>$1</web:CityName>
<web:CountryName>$2</web:CountryName>
</web:GetWeather>
</soapenv:Body>
</soapenv:Envelope>
</format>
<args>
<arg xmlns:m0="http://services.samples/xsd"
evaluator="xml"
expression="get-property('query.param.CityName')"/>
<arg xmlns:m0="http://services.samples/xsd"
evaluator="xml"
expression="get-property('query.param.CountryName')"/>
</args>
</payloadFactory>
<send>
<endpoint>
<address uri="http://www.webservicex.com/globalweather.asmx" format="soap12"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</resource>
</api>
4. Design API with two GET resource.
5. Go to the implement wizard and define HTTP endpoint (http://localhost:8281/weatheresb).
6. Go the manage wizard , select the tier then "save & publish".
7. Login to the store, subscribe to an application, then generate token.
8. You can use the SOAPUI to invoke this API.
Related posts:
i) http://www.vitharana.org/2015/01/soap-web-service-as-rest-api-using-wso2.html
ii) http://www.vitharana.org/2015/08/soap-webservice-as-rest-api-wso2-api.html