users@jersey.java.net

Re: [Jersey] Separation of Concern between Resource and Writer

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Tue, 06 Oct 2009 09:08:16 -0400

On Oct 6, 2009, at 6:58 AM, Jan Algermissen wrote:

> 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.
>
You can return an instance of Response with the entity embedded within
it, see the example I sent on the the thread "Accessing the response
object".

Marc.

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>