users@jersey.java.net

[Jersey] Re: UriInfo injection at resource initialization time

From: Markus Karg <karg_at_quipsy.de>
Date: Wed, 9 Mar 2011 12:34:37 +0100

>>> 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#Over
viewofJAX-RS1.0Features->>ConditionalGETsandReturning304%28NotModified%2
9Responses
>>> 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.

I understand you technical view, but see, from the spec actually it
actually is just "not mandatory", which means, it is not enforced to
work (as it cannot work due to technical constraints). If an implementor
would be able to make it work (maybe by magic) it actually wouldn't be
forbidden by the JAX-RS specification.

So, if you think it violates the spec, then you should file a bug report
agains JAX-RS 1.1, because we have to find an improved and clear
phrasing then (it then must say "MUST NOT" clearly).

But obviously nobody thought it must be explicitly forbidden as it
cannot be done without magic. So, in fact, it is jut "not mandatory"
currently, as odd as it sounds.

Regards
Markus