users@jersey.java.net

Re: [Jersey] Resource Filter Factory injectables

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 14 Apr 2010 09:40:00 +0200

On Apr 13, 2010, at 9:01 PM, John Lister wrote:

> Hi Paul, thanks for your pointers, I seem to have solved it...
>
> Firstly, I was trying to increase the logging level and was failing
> miserably, so download the source code (should have done this ages
> ago) and ended up stepping through the creation of my objects.
>

If you did not get by default any JCDI related output for classes it
means it was not enabled for those classes.

In your logs you should see stuff like:

INFO: Adapting InjectionTarget for
com.sun.jersey.samples.jcdibeans.resources.JCDIBeanPerRequestResource
in the scope interface javax.enterprise.context.RequestScoped
...
INFO: Binding the JCDI managed class
com.sun.jersey.samples.jcdibeans.resources.JCDIBeanPerRequestResource
in the scope javax.enterprise.context.RequestScoped to
JCDIComponentProviderFactory in the scope PerRequest


> A few things are going on.
> Firstly I seemed to have been using the wrong ManagedBean annotation
> javax.faces.jsf instead of javax.annotation - I'm sure I had tried
> the latter originally with no luck hence the switch.

Ug! i agree that is confusing.


> Also did 1.1.5 change anything as I recently updated the jersey libs
> on my glassfish box.
>

AFAIK there are no regressions related to this area between 1.1.4.1
and 1.1.5. We did fix an issue in 1.1.5:

   https://jersey.dev.java.net/issues/show_bug.cgi?id=423


> Secondly if I include the constructor, then using @ManagedBean cause
> an error on deployment because cdi can't find a default constructor.

Right.


> Using @ApplicationScope doesn't generate an error but doesn't inject
> anything.
>

Weld should log a warning. The bean is not getting instantiated by CDI
but by Jersey. The issue is you have not annotated the constructor
with @Inject and if you do you should get a deployment error. For
example, i get the following:

SEVERE: Exception while loading the app
org.glassfish.deployment.common.DeploymentException: Injection point
has unstatisfied dependencies. Injection point: parameter 0 of
constructor public
com
.sun.jersey.samples.jcdibeans.resources.Foo(javax.ws.rs.core.UriInfo);
Qualifiers: [@javax.enterprise.inject.Default()]

for:

@Path("/xxx")
@ApplicationScoped
public class Foo {

     @Inject
     public Foo(@Context UriInfo ui) {

     }


> Finally, removing the constructor and using either annotation does
> indeed work as expected - Again thought I had tried this combination
> before...
>
> Either way thanks for your pointers
>

I forgot to point out there is a sample that exercises a number of
areas of this functionality:

http://download.java.net/maven/2/com/sun/jersey/samples/jcdi-beans-webapp/1.1.5/jcdi-beans-webapp-1.1.5-gf-project.zip

Paul.