Note: In order to consume the openweathermap API you need to apply for an API key as outlined here: http://openweathermap.org/appid. But don’t worry, that’s easy to do and won’t take longer than two minutes!

Step 1: Create a new service class

Once you have your APPID, create a new service class with the following properties:

Include the full-qualified classname of the WeatherService class in the list of JAX-RS services specified in the web.xml configuration you did before. The corresponding element should now look like this:

Within the code we are obtaining a reference to an HttpDestination with the logical name openweathermap-destination via JNDI, hence we need to create that destination. For that purpose, double-click on the local server in the Servers view.

Switch to the Connectivity tab and click on the green + symbol to add a new destination. Enter the following information (replacing YOUR_APPID with the code you received when you registered with the openweathermap service.

Similar to what we have done to register the DataSource in the web.xml file, we also need to specify the HTTP destination in the web.xml file. Open it and enter the following code snippet underneath the already existing tag.

One more thing: it would actually be nice to be able to traverse the path and query for weather information in a more RESTful manner via a URL pattern like: /api/v1/cities/{id}/weather. Let’s add a respective method to the FavoriteCityService class:

Note: Since working behind corporate firewalls is a common cause of frustration I want to point out how to accommodate this. if your firewall requires a proxy for outbound communication you need to start your local server with proxy settings as follows:

In the Servers view, double-click the added server to open the editor.