users@jersey.java.net

Separation of Concern between Resource and Writer

From: Jan Algermissen <algermissen1971_at_mac.com>
Date: Tue, 06 Oct 2009 12:58:48 +0200

Maybe I am not seeing the obvious, but I have the following issue:

In my opinion it is good to have the destinction between resource
classes that take care of request handling and interactions with the
backend layer and message body writer classes that are responsible for
turning domain objects into the response body.

I am not sure if this is the intent of JAX-RS but I think that the
implementationof the writers should not be concerned with the
particularities of the actual request. This should be left to the
resource class.

It seems though that it is in some cases impossible (at least with
standard JAX-RS) to, for example, set headers (e.g. a Link header) in
the resource class and that instead one is forced to 'clutter up' the
writer implementation with handling the header population.

What I'd like to do instead is somehow assemble/compute the necessary
information in the resource class and pass it to the writer class.

What would be the best way to do this? Is the framework extensible in
a way that one could write annotations for this to inject the
information onto the writer?

Viewing this from the angle of the hypermedia constraint, the idea
would be to determine the links to be made available to the client
inside the resource class and pass that information to the writer
(because the writer must put the links into the message body) instead
of having the writer deal with determining the links itself.

Makes sense?

Jan