Thursday, June 14, 2007

Displaying Javadocs in Subversion

Javadocs are an essential component of any Java project. It is a convenient way for a developer to gain an understanding of the API and the prescribed ways to use it. This is especially true when hosting open source projects on Google Code or Sourceforge. Subversion is increasingly used as a revision control system to host source code and other project related artifacts. Google Code uses Subversion exclusively while Sourceforge provides it as an option. At times, for the convenience of hosting and to centralize resources it may be required to host the Javadocs in Subversion and access them via a browser. When using Eclipse as the IDE, connecting to a Subversion server is simple through the Subclipse plugin.

On successfully committing the Javadocs to the server and viewing the exported pages through a browser, we notice that the pages display in text and are not rendered as normal HTML pages by the browser (Screenshot). The reason behind this is that the MIME type for the pages is set to text/plain and must be changed to text/html. This can be achieved through the Eclipse UI by applying the MIME type to the svn:mime-type property on the root directory of the Javadocs. The Set property recursively option must be checked to ensure that all the pages under subdirectories are also updated with the correct type.

The last change is to update the MIME type of stylesheet.css to text/css. The Javadocs in Subversion can now be viewed successfully through a browser (Screenshot).

Tuesday, June 05, 2007

URLPing - A Java Utility to Ping a URL

Recently there was a need at work to programmatically check the status of a URL. The requirement was to test if a specified URL returned a HTTP Status Code 200 OK or otherwise. URLPing, the utility that I wrote has been hosted on Google Code and is available for download and reuse. The utility uses the Apache Jakarta Commons HttpClient component.

URLPing is the main class. This class provides two methods ping(String url) and ping(String url, int timeout). The first method accepts a URL to ping and defaults to a timeout of 30 seconds. The second method accepts a timeout interval in seconds in addition to the URL to ping.

URLPing urlPing = new URLPing();
PingResponse pingResponse ="");
assertEquals(pingResponse.getResponseStatus(), ResponseStatus.OKAY);

The response to the ping method is a PingReponse object. This contains a ResponseStatus enum with values of either OKAY, ERROR or TIMEOUT depending on the outcome of the ping. It also contains a responseCode property which contains the response code of the HTTP request.

Google Calendar Error Page

Don't come across Google products crashing very often, however this morning my Google Calendar instance crashed with a 'Server Error'. Well, Google Calendar is still in Beta and this is the first time it has crashed on me. I found the error page very interesting. It contained the same error message in 18 languages! Now that denotes an app with true internationalization...