Actually I realized this doesn't buy us anything.
Currently we just need call a static method call with id as parameter
whenever we need the object.
It really will be nice if we can inject the object to the needed methods
like @HeaderParam.
TIA,
Jun
-----Original Message-----
From: Marc.Hadley_at_Sun.COM [mailto:Marc.Hadley_at_Sun.COM]
Sent: Thursday, July 31, 2008 5:33 PM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Object injection
On Jul 31, 2008, at 5:24 PM, Grazi, Victor wrote:
> Is there any way to access the context directly via injection?
> It would be great if we could have an annotation for assigning a
> context property
You can inject ServletConfig, ServletContext, HttpServletRequest and
HttpServletResponse. So, e.g. if you want to get an object stored in the
servlet request by a filter you can write something like:
@Path(...)
public class MyResource {
public MyResource(@Context HttpServletRequest request) {
Object o = request.getAttribute(...)
...
}
...
}
HTH,
Marc.
>
> Thanks, Victor
>
> -----Original Message-----
> From: Li, Jun
> Sent: Thursday, July 31, 2008 5:19 PM
> To: users_at_jersey.dev.java.net
> Subject: RE: [Jersey] Object injection
>
> Great! We plan to create a resource base class for all the resources.
> Thanks,
>
> Jun
>
> -----Original Message-----
> From: Marc.Hadley_at_Sun.COM [mailto:Marc.Hadley_at_Sun.COM]
> Sent: Thursday, July 31, 2008 5:00 PM
> To: users_at_jersey.dev.java.net
> Subject: Re: [Jersey] Object injection
>
> Assuming you are using Servlets and the default per-request resource
> class lifecycle, then the filter could put the object in the servlet
> context and the resource class could extract it in its constructor.
>
> Marc.
>
> On Jul 31, 2008, at 3:47 PM, Li, Jun wrote:
>
>> Hi,
>>
>> I just wondering if there is a way to inject a object for all the
>> GET/PUT/POST/DELETE methods.
>> Basically, I have a session filter which extracts an id in the
>> header,
>
>> then I construct a object based on the id.
>> And I'd like to pass the object to all the methods in the resources,
>> so I don't need to have the exactly same code (although it is just
>> one
>
>> line) in each methods.
>>
>> Any suggestion?
>>
>> Thanks,
>> Jun
>>
>>
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>> Please access the attached hyperlink for an important electronic
>> communications disclaimer:
>>
>> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =
>> =====================================================================
>>
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>
> =
> =
> ======================================================================
> ======
> Please access the attached hyperlink for an important electronic
> communications disclaimer:
>
> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> =
> =
> ======================================================================
> ======
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> Please access the attached hyperlink for an important electronic
> communications disclaimer:
>
> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net
==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer:
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================