users@jersey.java.net

[Jersey] Re: Context injection in glassfish 3

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Thu, 05 Jul 2012 17:11:11 +0200

sample: http://search.maven.org/#search|ga|1|jersey-cdi

On 7/5/12 5:23 AM, Christopher Piggott wrote:
> That seems to actually work ...
> * Created a beans.xml
> * Added @Inject to my resource method
> * Added a parameter for the method-level context injection
>
> This is really messy, though. There are a bunch of methods, if each
> method needs to have everything it needs injected, that not only makes
> the code a lot messier but it means I can't take advantage of
> @RequestScoped any more.
>
> I'm wondering if you have any other alternatives. Or, could you
> explain to me the resource creation once CDI is enabled (which seems
> to happen simply by beans.xml being present). With jersey-guice in my
> standalone app I rarely used context injection - I did everything
> through guice.
>
> Is there a "How to use Jersey + Glassfish + CDI + Context Injections"
> sample or document somewhere?
>
> --Chris
>
>
> On Tue, Jul 3, 2012 at 10:42 AM, Pavel Bucek <pavel.bucek_at_oracle.com> wrote:
>> There are some limitation in injection, especially when you are working with
>> other injection frameworks. In that case, resource class instances are NOT
>> created by jersey and sometimes it just have no opportunity to inject own
>> objects.
>>
>> Putting @Context UriInfo ui into resource method parameter declaration
>> should work for you.
>>
>> Regards,
>> Pavel
>>
>>
>> On 6/27/12 6:11 AM, Christopher Piggott wrote:
>>> I am finding simple things that used to work great in a standalone
>>> servlet are not working so well in grizzly. I'm sure it's my fault.
>>>
>>> I can't figure out how to make context injections work:
>>>
>>> @Path("/wadl")
>>> @RequestScoped
>>> @ManagedBean
>>> public class Wadl {
>>>
>>> private static final Logger log =
>>> LoggerFactory.getLogger(Wadl.class);
>>> private byte[] wadlXmlRepresentation;
>>>
>>>
>>> @Context
>>> private UriInfo uriInfo; /* Always null */
>>> ...
>>>
>>> I have tried various combinations of @ManagedBean or not,
>>> @RequestScoped or not ... I didn't explicitly define any
>>> InjectableProviders for this, because I figured one would already be
>>> there.
>>>
>>> Essentially there's not much configuration in my hello world app.
>>> It's a war with a bunch of resource classes in it. The resources that
>>> don't need context injections work just fine.
>>>
>>>
>>> Shouldn't this just work?
>>>
>>>
>>
>