Tuesday, January 18, 2011

Restlet Part I

Representational State Transfer (REST) is a software architecture designed for use on the web.  Whereas the web is mainly used for interaction between a client and a server, REST allows for interaction between servers themselves.  It relies on an architectural usage of HTTP URLS which includes resources and verbs such as GET, PUT, DELETE, and POST.  For example, http://hawaii.com/news would have the resource (hawaii.com) and the verb GET (news).  Its action is to retrieve news from Hawaii.

A system like REST can be implemented with a Java framework called Restlet, which is the topic for today's blog post.  To introduce myself to this new framework, I practiced on four Restlet Code Katas.  Additional information on these katas can be found here.

Kata 1: Time resources
The task was to add three new resources to return the current hour, minute, and second.  I completed it in about 10 minutes.  Since it was the first introductory kata, the most difficult part was figuring out the actual resource and verb, which was localhost:8111/dateservice/[hour/minute/second].

The current month is January so the output corresponds to 0.
Kata 2: Logging
The task was to log Restlet's messages into a log file instead of having it display in the console.  The program was to read configuration settings from a properties file and use a handler to record all messages into a text file.  I completed this in about 2 hours.  The bulk of the time was spent trying to understand the whole process and just figuring out how to get it done.  A really handy explanation of logging is explained here.

Console output from Restlet is recorded into this log file.

Kata 3: Authentication
The task was to authenticate a user by asking for a username and password and verifying it against locally stored credentials.  Similar to Kata 2, this took me about 2 hours to complete.  Nearly all of the time was spent on research.  The solution can be found here.  Most of the problems I had were finding only outdated articles.  One article recommended using the class Guard, which was dated back to Java 1.4.

[Update (Jan. 24): I discovered that this feature is buggy.  The application does not always challenge the user with a username and password even after the server has been restarted.  I will update this section with an appropriate screenshot and reupload a new .zip distribution file once I figure out the problem.]

Kata 4: Wicket
The task was to create a client that could access the server via a webpage instead of the command line.  This required the use of the Wicket web framework.  I was able to complete this kata with about 6 hours of effort.  Several hours were wasted in debugging a client-to-server connection issue.  At first, I thought it might have been due to authentication but it turned out to be trivial problem.  The issue was due to a simple mismatch in ports; the server was being hosted on port 8111 but the client was trying to connect to 8112.

Basic webpage with buttons for requesting the date.

By completing these four katas, I learned the concepts of the Restlet framework.  I also learned the basics of networking in setting up a client and server side system.

A distribution of my files are available here.

No comments:

Post a Comment