Restlet

In my last post, I described I was implementing a SOAP web service controller between my Ruby chat bot and a CORBA component my company is developing. The WDSL for this service was straightforward, and with help from the Eclipse Web Service wizard, it was complete in no time.

I had some downtime before the CORBA module I needed to connect with was complete, so I began to look into re-implementing my controller as a REST web service. A little digging led me to Restlet. Restlet is a lightweight framework for developing REST web services in Java. I've seldom had an easier time integrating a new Java package and getting something up and running.

Restlet comes bundled with it's own HTTP server, but I opted to deploy a WAR file to our existing Tomcat installation. There are three basic steps needed to get this to work.
  • Creating a Resource is the first step. The Resource is the brains of your service. It captures request parameters (from the URL or encoded in the body), then takes the appropriate action dictated by the HTTP method (GET, PUT, POST, or DELETE). The Resource can allow the user to specify a preferred format for for the response (html, text, xml, etc.) and it determines which HTTP response code to return to the caller.
  • The next step in implementing a Restlet application is to create a Restlet Application class. This class must implement the createRoot method. This method maps incoming requests to your Restlet resources (similar to JSF navigation_rule or Ruby's routes.rb file) .
  • The final step in creating the REST service is link your Application to Restlet servlet in your web.xml.

Testing this service was kind of fun. At first I used a web browser to submit various requests, but I finally integrated this with my Chat bot using the rest-open-uri Ruby gem described in RESTful Web Services (which is a great book).

Comments

Popular posts from this blog

I Believe...

FRail :include

Cognitive Dissonance?