Pages

Saturday, January 22, 2011

Restlet Katas Part II

Overview
This is only my second experience with Restlet, but I am getting more used to it, slowly but surely. I feel like this second exercise has given me much more insight about how Restlet works. The whole framework seems to be very client/server oriented and as a result I've been getting a lot of practice studying and programming the relationship between a client and server. Also, I'm actually starting to enjoy programming with Restlet as it uses Java which makes everything pretty straight forward and when I run into a problem I can always find the solution because there are so many resources for Java programming.

For this task we were asked to modify a pre-made Restlet project which allows for the storage, retrieval, and deletion of contacts using the put, get, and delete. There were three katas which ranged in difficulty: adding a new resource which would get all contacts in the system, adding support for get-all and delete-all, and finally adding a new parameter to the Contact class. In the following section I will go over my experiences with completing each kata.

Restlet Contact Service Katas
These additional katas were designed to help us learn a bit more about the Restlet framework and after completing these katas I feel that I am slowly getting more and more familiar with Restlet.
  • Kata 5: Modify the system to support a new resource called "contacts" and its associated URL: http:///contactservice/contacts. This resource only supports the GET operation and when it is invoked, it returns an XML representation of all of the contacts in the system.
    Completed: Yes
    Time Spent: 2 hours 10 minutes

    Summary: I think this kata took the longest because I had to actually sit down and study the code to figure out what each part did, before I could successfully finish it. Initially I tried to do the kata without studying the code, this ended up with me finishing it, but sloppily. After running an ant verify I realized how sloppily I had done this kata, so I went back and restructured my code from scratch. The second time around I had a much better idea of what I was doing and I finished it rather quickly. The hardest part for me was figuring out how to determine the host programmatically, after a long time searching I finally figured out I could use the following line:

         String host = getRequest().getRootRef().toString();

    After solving that, I ran into the issue of figuring out how to output the data in XML format; after studying the code for a few minutes I figured it out fairly easily.

  • Kata 6: Now that you have a contacts resource, extend the command line client to support a "get-all" and "delete-all" operation.
    Completed: Yes
    Time Spent: 1 hour 35 minutes

    Summary: I had a pretty good idea how to do this when starting the kata, though things didn't go as smoothly as I had planned. The first time I tried to complete this kata, I kept getting a NoClassDef error. I tried searching for a solution, but no matter what I tried I couldn't figure out why I was getting the error. I started from scratch a second time and made sure to test every little milestone of the kata I completed. Doing so helped me finish the kata without issue, like the first time.

  • Kata 7: Add a telephone number to the Contact resource, which only supports numbers and dashes.
    Completed: Yes
    Time Spent: 1 hour

    Summary: I actually completed this kata first, because it was the easiest of the three katas. Solving this kata was fairly easy, as we just had to add a new parameter to the Contact class. It was just a matter of looking at how the other parameters of the Contact class were used throughout the system, and just modifying the code to support the extra "phone" parameter. The hardest part of this kata was figuring out how to set the error status, if the phone number the user entered had something other than numbers and dashes. Checking for the numbers and dashes was simple using a regular expression, but I couldn't set the response using the piece of code:

         getResponse().setStatus(Status.CLIENT_ERROR_NOT_ACCEPTABLE);

    After trying to get this working unsuccessfully I consulted with my professor, and I felt really foolish when I realized it was because I was performing the validation in the wrong file. I was suppose to do the check in the ContactResource.java file, but instead I was doing it in the ContactClient.java file. After I moved the check to the proper file everything worked as expected.
Deliverables

No comments:

Post a Comment