users@jersey.java.net

[Jersey] Re: UriInfo injection at resource initialization time

From: Martin Matula <martin.matula_at_oracle.com>
Date: Wed, 09 Mar 2011 12:27:32 +0100

On 9.3.2011 12:16, Markus Karg wrote:
>> UriInfo injection in constructor is used in an example in "Overview of
>> JAX-RS 1.0 Features"
>> http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features#OverviewofJAX-RS1.0Features->ConditionalGETsandReturning304%28NotModified%29Responses
>> It also says "Notice that in this example the constructor of a
>> resource class can be used perform actions that may otherwise have to
>> be duplicated to invoked for each resource method".
>> That makes perfect sense to me - but are you saying this wouldn't
>> work in Jersey?
>> I see a good specification/implementation letting me be flexible with
>> my code, instead of making me bend my code to fit it.
> Apparently it is not working in Jersey as you experienced and was explained already. See that this functionality is not mandatory by the JAX-RS 1.1 specification, so relying on that possibility would bind your code to a particular implementation, which is not what you want.
Not mandatory? :) I mean, this is same as referencing an instance
variable in Java from a static context. Would you say it is not
mandatory to support that? I'd say it is impossible to support and
"supporting it" (whatever that means) violates the spec and common sense
logic.
Martin