Container Independence

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Fri, 06 Apr 2007 13:47:48 -0400

>> Right, but wrt container independence, the question is whether the
>> JSR 311 class needs to know that its attached to a Restlet Router or
>> not - i.e. can I write the application code independent of whether
>> the code is deployed as a Servlet or using Restlet.
> In my opinion it doesn't need to know this. All the necessary context
> information can be injected into the Resource and the input
> Representations
> (entities). All the response information (custom status,
> redirection, etc.)
> could be dynamically extracted by the container. This would ensure
> a better
> separation of concern between the Resources/Representations and their
> containers.
I don't follow what you are proposing on the response side, could you
give an example of what you mean ? E.g. how would you propose that a
JSR 311 resource class issue a redirect ?

> I'm not proposing that the Resources have any knowledge on the parent
> container. The code based on JSR311 should be dependent on the
> Servlet API
> or on the Restlet API.

Hmm, I could read that one of two ways. Either "code based on JSR
311" means the runtime code supporting an application built using the
JSR 311 APIs -- or -- you mean something other than Servlet, Restlet,
etc when you write "parent container".

My main concern is that a class written using the JSR 311 APIs should
be portable between implementations based on different underlying
technologies (Servlet, Restlet, ...). I'm not against injecting
something technology specific for those cases where the class wants
to do something tchnology-specific but that shouldn't be the norm.

> For the deployment into a Servlet or Restlet
> container, we might need to make a few modifications. For the
> Restlet API,
> that would be very minor:
> attach(String uriPattern, Class<? extends Resource> targetClass)
> could become :
> attach(String uriPattern, Class targetClass)
> and the container would recognize annotated Resource classes
> automatically.

Right, you could easily extract the uriPattern value from the
@UriTemplate annotation and generate the required attach methods
using apt. Alternatively you could just have a

attach(Class targetClass)

that extracts the UriTemplate value using reflection.


Marc Hadley <marc.hadley at>
CTO Office, Sun Microsystems.