Welcome Guest! Log in
Due to some maintenance operations, stambia.org will be switched to read-only mode during the 13th November. It will be possible to read and download, but impossible to post on the forums or create new accounts. For any question please contact the support team.


In this article

Sometimes, webservice suppliers do not provide a WSDL. This is often the case when the webservice consists in a simple HTTP GET Method.

This article shows how to call this kind of webservice in Stambia, using a WSDL metadata.

The webservice

We are going to work with the "OpenWeatherMap" webservice for getting the current weather in a given city.

Note : OpenWeatherMap is not a service supplied by Stambia.

Note that the request has parameters, especially the city name, the desired response format, and the API KEY.

You'll have to create a free account on http://openweathermap.org/ to get your api key.

 

Creation of the WSDL metadata

Create a new Wsdl metadata file:

newmetadata

 

Under the Wsdl node, right click and create a Service node and a Port node.

The Wsdl node and the Service node only need the Name property to be set (for example "openWeatherMap" and "openWeatherMapService").

Here is the properties for the Port node:

  • Name: openWeatherMapHttpApi
  • Address: http://api.openweathermap.org/data/2.5
  • Protocol: HTTP
  • Http Verb: GET (if this property is not displayed, save/close/reopen your metadata first, this is a known issue)

 

createPortNode

 

Create a new Operation under openWeatherMapHttpApi:

  • Name: getForecastAsXml
  • Address: /forecast?q={cityname}&lang={lang}&units={units}&mode=xml&APPID=YOUR_APP_API_KEY

Note: If you want to use json change mode=xml to mode=json

createOperationNode

 

Note the parameters in the URL : the curly brackets will help Stambia know that these are placeholders for parameter values.

 

Declaration of the input parameters

Now, we need to declare the Input parameters of the service. For this, we create a new Input section, with 3 "Part" nodes :

createCityPartcreateLangPart  createUnitsPart

 

Note: Instead of {params} in the URL and "http:urlReplacement" Binding type, we could use "http:urlEncoded" Binding type. The parameters in this case are automatically added to the URL with the form ?<Name>=<value>&<Name>=<value>&...

 

Reversing the response in an output parameter

XML response

The webservice response is in XML form, because we specified the XML mode. If you chose json mode, go to the next part.

We are going to reverse this XML and incorporate the result in our WSDL.

We will do that in three steps :

1) Retrieve the response in a file

2) Create a XML Metadata with this File

3) Copy the node we want from the XML Metadata to the WSDL metadata

1) Retrieve the response in a file

Retrieve sample response of a call to the web service, with going to this URL for example :
http://api.openweathermap.org/data/2.5/forecast?q=London&mode=xml&units=metric&APPID=YOUR_APP_API_KEY
-> Save the output in a File, you can name it openWeatherMapHttpApiOutput.xml.

2) Create an XML Metadata

Create a new XML Metadata, named xmlOutput, for example.

  • Use the file containging the response we retrieved for Default XML Path
  • generate an Xsd File, by clicking on the generate button, you can name it openWeatherMapHttpApiOutput.xsd
  • Then click refresh and select the good node, here 'weatherdata'
  • Click on reverse and Finish

 xmlWizard

You should have this :

xmlOutputReversed

Note : if your location attributes (altitude, geobase, geobaseid, latitude and longitude) are reversed into the root/location element instead of root/location/location, this is a known bug. You can drag and drop them to the correct location to have the same thing as the screenshot.

3) Create the Webservice Output parameter

Now, we are going to use the XML metadata we just created for the ouput parameter of our WSDL.

Open the webservice metadata and create a new Output parameter

newOutput

 

Create a new part in this Output, you can call it results

Next, create the root node of the results, by creating a new 'element' named 'weatherdata' on the results part.

Then, open the XML Metadata, and copy the sequence node

copySequenceNode

 

Finally, paste the Sequence in the weatherdata element of the WDSL.

You have now the output parameter of your webservice, which you can use to get the result of an invocation of the webservice in Mappings

openWeatherMapMetadataFinal

 

JSON response

If you chose the json mode, reversing the response is very simple

Open the webservice metadata

Create a new Output parameter

newOutput

Create a new part in this Output, you can call it results

Next, right click on results and choose Launch JSON Object Wizard :

launchJSONObjectWizard

 

We will use a sample JSON Request URL to reverse the response :

http://api.openweathermap.org/data/2.5/forecast?q=London&mode=json&units=metric&APPID=YOUR_APP_API_KEY

JSONWizard

Note :

  • Do not forget to click on Reverse
  • You could use too a Sample File (which contains the sample response) or Reverse directly from the Clipboard

Finished ! You have now the output parameter of your webservice, which you can use to get the result of an invocation of the webservice in Mappings

openWeatherMapMetadataJSONFinal

 

Webservice invocation

We are going to create a mapping which call the webservice for a list of cities, fetched from the Stambia tutorial database.

Mapping overview :

MappingGetWeatherOverview

A few comments:

  • The source table is T_ADDRESS, from the Stambia Demo database.
  • We added a filter for playing with only a few cities : T_ADDRESS.CUS_ID in (1, 10, 40, 50)
  • Note the "getForecast" node is a key node, it is required to set it, here we mapped it to the ADR_ID field.
  • We are using the metadata with the xml response, but for json the operation is the same

Integration Parameters:

integrationOptions

  • Out File Name is used to indicate the file in which results will be aggregated
  • Sent Messages Folder is a folder in which the messages sent by the runtime to the web service will be stored (optional, usefull for debug, to see exactly what's sent)
  • Received Messages Folder is a folder in which the messages received from the web services will be stored (optional, usefull for debug, to see the responses of the web services)

 

Using the result

 Let's see now how to use the output/response of the webservice to load a table.

Mapping overview:

MappingGetWeatherWithTargetOverview

 

  • We are loading here the latitude and longitude of the T_ADDRESS Demo table from the web service.
  • Note that we use the getForecastAsXml node to map the T_ADDRESS_2.ADR_ID.

 

Comments  

# Emmanuel Rambeau 2015-10-13 16:54
Bonjour,

Depuis le 9 octobre OpenWeatherMap demande obligatoirement une clé pour l'API. En particulier, cela pose problème car on ne peut pas définir le port node ainsi : http://api.openweathermap.org/data/2.5

Il pourrait être intéressant de repasser dessus pour adapter l'article en conséquence.
Sinon, le tuto est très bon.
# Thomas BLETON 2015-10-13 17:11
Merci pour ce retour ! Nous allons regarder comment prendre en compte ce changement du service OpenWeatherMap.
# Thomas BLETON 2015-11-17 09:56
I forgot to mention that we adapted the article for adding the APPID to the examples. This is done now :)
# cenisisois 2017-04-21 14:51
Hi,

I have problem with using result of WebService, when i use regular expression in my mapping il must to execute the mapping in "Staging Area" and in this situation i lose my data.

When i use result in mapping without regular expression and i execute it in "Source" i dont have any problem.

For information in the result of WebService i have Greek letter.

Thank you for your hellping

Best regards,
# Thomas BLETON 2017-04-21 17:00
Hi, I would suggest you open a support ticket for this particular issue.

You have no rights to post comments

Articles

Suggest a new Article!