Distribution: http://ics414-spring2011.googlecode.com/files/restlet-contactservice-gburgess-1.0.122.zip
This past week my ICS 414 class dove deeper into Restlet. Interestingly, we started using XML, which had me overjoyed, because I've had quite a bit of self-taught experience with XML, webservices and java. Sufficed to say the assignment this week was pretty simple. After completing the assignment, I ended up with a cute non-persistant local server hosting a little webservice that sent both XML and Java objects back and forth between client and server applications.
The back-end(java) database used for this assignment was a single, static (black magic!) class that held a map between keys and values. The important part was the static declaration, which meant that StaticClass.class.get() from anywhere returned the database. Pretty nifty.
As disussed in a previous post, the REST interface supports GET, PUT, POST and DELETE protocols for resources living on the web. You may be asking yourself how XML fits into the equation. Well, most webservices available online or over intranets usually pass data formatted as XML. XML is extremely well suited to being a "go between" language as data and metadata can be presented in a universally-readable format. In fact, many proprietary software systems (I'm looking at you Microsoft) use XML as a back-end data storage mechanism. If you think about it, this is pretty handy, it means that you, the average (or maybe not so average) Joe can parse data out of these files (granted theres a lot of meta-garbage floating around in there).
DOM (Document Object Model) is used extensively in XML based webservices. Basically its a Document object (read: box) that has a root element (read: tree). The nice thing is that because XML is well suited to handling objects, so Java objects translate over nicely, and since XML is implemented as a linked-list/tree heiarchy, you can easily loop/iterate through the whole thing, pulling whatever data you need. Handling these DOM objects in Restlet is a bit troublesome (LOTS of auxilliary method calls), however it should be noted that most XML extention libraries have fairly simmiliar method names. One of the cool things about Java is that it supports a system by which XML and Java Objects can be encoded and decoded between eachother. This is extremely useful as constructors on the Java side can be passed XML representations of Objects, saving you a bunch of method calls.
If your planning on investigating on your own, here are a few tips:
1. Make sure you're using a browser that can parse XML (almost anything except chrome and safari), or else the tags will disappear, and you'll never know whats going on.
2. If in doubt about traversing/handling the DOM, getChildNodes() will return a NodeList of child nodes, and getItem(x) will return the node at position x in a NodeList.
3. You may have to call getChildNodes() twice to get to the NodeList that contains all the data.
As for the Katas:
Kata 05: Agregate Contacts
This kata focused on creating a DOM object that held the URIs of objects in the database. My experience with the DOM system made this one pretty easy, less than two hours.
Kata 06: Implement a get-all and delete-all command for the database
This was more like Kata 05 pt II, basically parsing the URI's from the first part and getting the data out of each link in order to display. Deletion was even easier, just grab the unique ID and call delete(). <2hrs
Kata 07: Extend Contact to implement a phone number
Easy peasy, until I had to deal with a FindBugs/PMD argument over somestupid Exception. Basically updating the Contact object, and all calls & adding the phone number variable to various locations. <2hrs
Distribution:
http://ics414-spring2011.googlecode.com/files/restlet-contactservice-gburgess-1.0.122.zip
No comments:
Post a Comment