The Katas are as follows:
Kata 5: Contacts resource (~3 hours)
For this particular Kata, we we modified the Restlet system to support a new resource called "contacts" and its associated URL: http://<host>/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. To support the RESTful style of hypertextual links, the XML had to look like the following:
<contacts>
<contact>http://host/contactservice/contact/ID</contact>
<contact>http://host/contactservice/contact/ID</contact>
</contacts>
The actual <host> and actual <ID> for all <contact> elements are substituted and returned in the XML.
This requires the system to programmatically determine the URL of the current host. We accomplished this by use of this type of call inside of the ServerResource method:
getReference().getHostDomain() ... etc.
We also needed to extend the createInboundRoot() method to support the new resource, and add a new package, class, and associated unit test. Overall, there was quite a bit of code to be added. One had to understand the use of objects:
- DomRepresentations (org.restlet.ext.xml)
- Document (org.w3c.dom)
- Element (org.w3c.dom)
to implement the changes required to access the resource "contacts" and have it display the information "put" into memory storage. I did not know that chrome and safari automatically translated XML when viewed. I wasted much time on this trying to figure out why my pages weren't showing up.
Kata 6: Command line client manipulation of Contacts resource (~3 hours)
After we implemented the contacts resource, we were required to extend the command line client to support a "get-all" and "delete-all" operation.
The get-all operation had to invoke the GET contacts command to get the XML representation containing links to all the contacts, then extract the URL of each contact and perform a GET to retrieve its representation. Then print out the contact info associated with that URL (I.e. first name, last name, info). The main changes had to be done in ContactClient.java.
The next step, which used the get-all operation, was delete-all operation. This operation had to use the GET contacts command to get the XML representation containing links to all of the contacts, then extract the URLs, then call DELETE to delete them. Sample output can be seen below.
I had a few odd thread errors during this kata (i.e. concurrentHashMap was having issues). I'm still not exactly sure how I fixed it, honestly. I ended up having to wipe my set up at least once and rebuild. The (only) good part about having to redo some work is that it reinforced quite a bit of knowledge imparted to us by Professor Johnson.
The final kata required the extension of the Contact resource to include a telephone number. The telephone number must contain only numbers and the "-" character. The following regular expression validates that the user has inputted a number-number format.
Pattern p = Pattern.compile("^\\d+(-\\d+)+");
Thus, when clients do a PUT of a Contact representation in XML format, the server checks that the telephone number field has the correct format and set the Status field to indicate an error if the telephone number is incorrectly formatted. Both unit tests to check valid input and invalid input are provided in my distribution.
A link to my distribution file can be found here



No comments:
Post a Comment