Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jersey-dev] Cannot @Inject into ExceptionMapper

https://github.com/eclipse-ee4j/jersey/issues/4436

On Mon, Apr 6, 2020 at 9:12 PM Martynas Jusevičius
<martynas@xxxxxxxxxxxxx> wrote:
>
> Thanks Jan.
>
> I'll create issues for what I think are bugs.
>
> Where is the place to ask general questions? StackOverflow? Because I
> have quite a few of them, now that I'm upgrading from 1.x.
>
> On Mon, Apr 6, 2020 at 5:15 PM Jan Supol <jan.supol@xxxxxxxxxx> wrote:
> >
> > Hi,
> >
> > This mailing list's primary purpose is not for solving bugs, rather it
> > should be used for a discussion and announcements.
> >
> > Feel free to file us an issue on our bug tracker
> > https://github.com/eclipse-ee4j/jersey/issues and provide a reproducer,
> > best in a form of JerseyTest or a standalone github project.
> >
> > I tried to reproduce the issue, but no success. What comes on my mind
> > right now is that you try to inject out of the Request scope, or I have
> > seen a similar issue when multiple classloaders were involved.
> >
> > Thanks,
> >
> > Jan
> >
> > On 04.04.2020 13:09, Martynas Jusevičius wrote:
> > > TemplateCallProvider is a Factory:
> > >
> > > @Provider
> > > public class TemplateCallProvider implements Factory<TemplateCall>
> > >
> > > On Sat, Apr 4, 2020 at 1:05 PM Martynas Jusevičius
> > > <martynas@xxxxxxxxxxxxx> wrote:
> > >> Hi,
> > >>
> > >> I'm attempting to inject some RequestScoped objects into an ExceptionMapper:
> > >>
> > >>      public class NotFoundExceptionMapper extends ExceptionMapperBase
> > >> implements ExceptionMapper<NotFoundException>
> > >>      {
> > >>
> > >>          @Inject TemplateCall templateCall;
> > >>      ...
> > >>
> > >> In my ResourceConfig I have
> > >>
> > >>      register(new AbstractBinder()
> > >>      {
> > >>          @Override
> > >>          protected void configure()
> > >>          {
> > >>              bindFactory(TemplateCallProvider.class).to(TemplateCall.class).
> > >>              proxy(true).proxyForSameScope(false).in(RequestScoped.class);
> > >>          }
> > >>      });
> > >>      ...
> > >>      register(new NotFoundExceptionMapper());
> > >>      // register(NotFoundExceptionMapper.class); // also tried this, same effect
> > >>
> > >> However I get an error when NotFoundException should be mapped:
> > >>
> > >> 04-Apr-2020 10:57:22.213 SEVERE [main]
> > >> org.apache.catalina.core.ApplicationContext.log Servlet.init() for
> > >> servlet [com.atomgraph.server.Application] threw exception
> > >> MultiException stack 1 of 2
> > >>          java.lang.RuntimeException: java.lang.InstantiationException:
> > >> com.atomgraph.processor.util.TemplateCall_$$_jvstb48_0
> > >>                  at
> > >> org.jvnet.hk2.internal.ProxyUtilities$4.run(ProxyUtilities.java:157)
> > >>                  at java.security.AccessController.doPrivileged(Native Method)
> > >>                  at
> > >> org.jvnet.hk2.internal.ProxyUtilities.secureCreate(ProxyUtilities.java:128)
> > >>                  at
> > >> org.jvnet.hk2.internal.ProxyUtilities.generateProxy(ProxyUtilities.java:194)
> > >>                  at
> > >> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2074)
> > >>                  at
> > >> org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:666)
> > >>                  at
> > >> org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:54)
> > >>                  at
> > >> org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:988)
> > >>                  at
> > >> org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:998)
> > >>                  at
> > >> org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:976)
> > >>                  at
> > >> org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.inject(AbstractHk2InjectionManager.java:202)
> > >>                  at
> > >> org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.inject(ImmediateHk2InjectionManager.java:30)
> > >>      ...
> > >> MultiException stack 2 of 2
> > >>          java.lang.IllegalArgumentException: While attempting to create
> > >> a Proxy for com.atomgraph.processor.util.TemplateCall in scope
> > >> org.glassfish.jersey.process.internal.RequestScoped an error occured
> > >> while creating the proxy
> > >>                  at
> > >> org.jvnet.hk2.internal.ProxyUtilities.generateProxy(ProxyUtilities.java:201)
> > >>                  at
> > >> org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2074)
> > >>                  at
> > >> org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:666)
> > >>                  at
> > >> org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:54)
> > >>                  at
> > >> org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:988)
> > >>                  at
> > >> org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:998)
> > >>                  at
> > >> org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:976)
> > >>                  at
> > >> org.glassfish.jersey.inject.hk2.AbstractHk2InjectionManager.inject(AbstractHk2InjectionManager.java:202)
> > >>                  at
> > >> org.glassfish.jersey.inject.hk2.ImmediateHk2InjectionManager.inject(ImmediateHk2InjectionManager.java:30)
> > >>      ...
> > >>
> > >> Looking at similar problems online, my guess is that it has to do with
> > >> a RequestScoped object being injected into Singleton. However I
> > >> haven't been able to find a solution yet.
> > >>
> > >> Thanks.
> > >>
> > >>
> > >> Martynas
> > > _______________________________________________
> > > jersey-dev mailing list
> > > jersey-dev@xxxxxxxxxxx
> > > To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jersey-dev
> > _______________________________________________
> > jersey-dev mailing list
> > jersey-dev@xxxxxxxxxxx
> > To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jersey-dev


Back to the top