users@jersey.java.net

Re: [Jersey] _at_Context annotation...

From: Lars Tackmann <lars_at_randompage.org>
Date: Thu, 10 Jul 2008 10:19:02 +0200

On Wed, Jul 9, 2008 at 6:15 PM, Bob Namestka <Robert.Namestka_at_sun.com> wrote:
> Hello All,
>
> I'm a relative Jersey noob. I'm using jersey-08 for my prototyping.
>
> Question: When using:
>
> @Context
> private UriInfo context;
>
> inside of a (sub)Resource class, should that context be available anywhere
> in the Resource chain ?
>
> In other words, given:
>
>
> http://somewhare.com/myapp/users/user123/trinkets/sku456
>
> and have implemented classes for:
> UsersResource, UserResource, TrinketsResource and TrinketResource
>
> following the pattern(s) in the jersey examples, and using:
>
> @Context
> private UriInfo context;
>
> inside of TrinketResource, should context be non-null ?

No @Context can only inject into resource classes that themselves is
annotated with path (root resources). If you
need it in a sub resource then you must explicitly pass it on in the
constructor.

Here is a (root) resource that uses this technique:
http://svn.randompage.org/java/samples/jax-rs/acegi/src/main/java/org/randompage/samples/jaxrs/acegi/resources/UsersResource.java

here is the sub resource it uses
http://svn.randompage.org/java/samples/jax-rs/acegi/src/main/java/org/randompage/samples/jaxrs/acegi/resources/UserResource.java

Hope that helps.



-- 
Yours sincerely
Lars Tackmann