This documentation is for WSO2 API Manager 2.1.0 View documentation for the latest release.
Using WSO2 ESB Connectors in the Mediation Flow - API Manager 2.1.0 - WSO2 Documentation

All docs This doc
||
Skip to end of metadata
Go to start of metadata

WSO2 ESB supports a rich set of Connectors which enabled it to seamlessly integrate with various third party services. WSO2 API Manager can be used to manage the API of the connector which is exposed via WSO2 ESB. The following describes the high level steps to expose the Open Weather Map connector added to WSO2 ESB via the API Manager.

What is described in this page is a high level use case of using a connector in the mediation flow, using an example. For in depth details and samples in using connectors, please see the documentation on WSO2 ESB and supported Connectors.

  1. Download the Open Weather Map connector from WSO2 Connector Store.
  2. Download the start the WSO2 ESB with a port offset of 1.
  3. Import the Open Weather Map Connector to ESB following the documentation on Working with Connectors via the Management Console.
  4. Create an account in Open Weather Map service, and obtain the API key as explained in Configuring OpenWeatherMap Operations.
  5. Create a Rest API in WSO2 ESB which will initialize the Open Weather Map connecor and invokes it. The following sample sequence invokes the getCurrentWeatherForOneLocByCityName operation:

    <api xmlns="http://ws.apache.org/ns/synapse" name="OpenWeatherMapAPI" context="/openWeatherMapApi">
       <resource methods="POST GET" url-mapping="/*">
          <inSequence>
             <property name="apiUrl" expression="json-eval($.apiUrl)"/>
             <property name="apiKey" expression="json-eval($.apiKey)"/>
             <property name="apiVersion" expression="json-eval($.apiVersion)"/>
             <property name="cityName" expression="json-eval($.cityName)"/>
             <property name="countryCode" expression="json-eval($.cityCountry)"/>
             <openweathermap.init>
                <apiUrl>{$ctx:apiUrl}</apiUrl>
                <apiKey>{$ctx:apiKey}</apiKey>
                <apiVersion>{$ctx:apiVersion}</apiVersion>
             </openweathermap.init>
             <openweathermap.getCurrentWeatherForOneLocByCityName>
                <cityName>{$ctx:cityName}</cityName>
                <cityCountry>{$ctx:cityCountry}</cityCountry>
             </openweathermap.getCurrentWeatherForOneLocByCityName>
             <respond/>
          </inSequence>
       </resource>
    </api>

    For the complete list of supported operations, please refer the documentation on Configuring OpenWeatherMap Operations.

  6. Expose this ESB API from API Manager, by creating an API in API Publisher and providing the ESB API as the endpoint.
  7. Subscribe to the API created from API manager and invoke it. The apiKey should be the key obtained by creating an account in the Open Weather Map site. A sample payload is shown below:

    {
      "apiUrl":"http://api.openweathermap.org",
      "apiKey":"xxxxxxxxxxxxxxxxxxxxxxxxxxx",
      "apiVersion":"2.5",
      "cityName":"London",
      "cityCountry":"uk"
    }
  • No labels