March 2, 2010 at 10:26 pm · Filed under Java
I’ve also been spending quite a lot of time with a friend developing a Java Weather API, which is now almost nearing completion (85th revision and counting). I’ve been using the API as part of a larger system that monitors climate conditions in certain locations during the course of a year, collating the results which will later be used to generate graphs and other statistics.
The API is pretty simple, but certainly effective, and makes use of Google’s own weather API that’s provided as a SOAP service.
The API parses the XML feed given by Google, and constructs Weather objects that can then further be manipulated.
Here’s a simple example of how the API could be used:
try
{
Weather weather = WeatherStation.getWeather("wirral");
}
catch(WeatherStationException wse)
{} // Bad!
weather.getConditions(); //Returns a string, such as "Fog", "Partly Cloudy"
weather.getTemperature(); //Default is to return result in degree celsius
As with my last post, we do fully intend to make these APIs available publicly at some point in the near future.
March 2, 2010 at 10:05 pm · Filed under Java
I’ve spent the past couple of hours completing a first revision for a Java API that makes use of the excellent HtmlUnit libraries to enable monitoring of a web servers response time.
Here’s a simple example of how I’d implement the API:
String[] siteUrls = {"http://www.bingo.com",
"http://www.microsoft.com",
"http://www.google.com"};
for (String url : siteUrls)
{
Website test = new Website(url);
System.out.print("Site: ");
System.out.println(test.getSiteUrl());
for (int i = 0; i < 2; i++) {
System.out.println("\tTest " + i + ":");
System.out.println("\t\tCreated: " + test.getCreateDate());
System.out.println("\t\tResponse time: " + test.getResponseTime() + "ms");
System.out.println("\t\tTime of last refresh: " + test.getLastRefreshed());
}
System.out.println();
System.out.println("");
}
Which gives:
Site: http://www.bingo.com
Test 1:
Created: Tue Mar 02 20:29:29 GMT 2010
Response time: 149ms
Time of last refresh: Tue Mar 02 20:29:30 GMT 2010
Test 2:
Created: Tue Mar 02 20:29:29 GMT 2010
Response time: 100ms
Time of last refresh: Tue Mar 02 20:29:31 GMT 2010
Site: http://www.microsoft.com
Test 1:
Created: Tue Mar 02 20:29:31 GMT 2010
Response time: 507ms
Time of last refresh: Tue Mar 02 20:29:33 GMT 2010
Test 2:
Created: Tue Mar 02 20:29:31 GMT 2010
Response time: 361ms
Time of last refresh: Tue Mar 02 20:29:34 GMT 2010
Site: http://www.google.com
Test 1:
Created: Tue Mar 02 20:29:34 GMT 2010
Response time: 86ms
Time of last refresh: Tue Mar 02 20:29:35 GMT 2010
Test 2:
Created: Tue Mar 02 20:29:34 GMT 2010
Response time: 85ms
Time of last refresh: Tue Mar 02 20:29:35 GMT 2010
The idea is that I’ll use this API in a bigger project I’m working on, a simple OpenSource website monitoring/reporting suite.
Still a lot of work to do, leave a comment if you’d like to take a closer look at the API. I do intend to make a public SVN server at some point and start porting over some of these little projects.