users@glassfish.java.net

Re: [Jersey] Re: _at_Context UriInfo causes "Exception creating stateless session bean"

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Tue, 27 Sep 2011 10:07:31 -0700

Thanks,

~Jakub

On 25.9.2011 13:35, Antonio Goncalves wrote:
> Here it is : http://java.net/jira/browse/JERSEY-781
>
> Antonio
>
> 2011/9/19 Jakub Podlesak <jakub.podlesak_at_oracle.com
> <mailto:jakub.podlesak_at_oracle.com>>
>
> Hi Antonio,
>
> Indeed, looks like JSF/EJB/JAX-RS do not go well together
> in GlassFish. Could you please file a new issue in [1] and attach
> a simple
> reproducible test case there? Ideally a maven based project?
>
> Thanks,
>
> ~Jakub
>
> [1]http://java.net/jira/browse/JERSEY
>
>
> On 17.9.2011 21:04, Marek Potociar wrote:
>
> Forwarding to Jersey users mailing list as the issue seems
> related to Jersey/GF EJB integration.
>
> Marek
>
> On 09/17/2011 05:50 PM, Antonio Goncalves wrote:
>
> Hi all,
>
> I have a JSF managed bean invoking a Stateless bean with
> REST interface. Everything works fine until I use a @Context
> UriInfo in the EJB. It looks like this.
>
> The managed bean injects a reference of the EJB and
> initializes the message attribute in the @PostConstruct :
>
>
> @ManagedBean
> public class MyController {
>
> @Inject
> private MyEJB myEJB;
>
> private String message;
>
> @PostConstruct
> private void initList() {
> message = myEJB.displayMsg(42L);
> }
>
> public String getMessage() {
> return message;
> }
>
> public void setMessage(String message) {
> this.message = message;
> }
> }
>
> The Stateless EJB has a @Path annotation and a @Get method
> that just returns a String :
>
>
> @Stateless
> @Path("/msg")
> public class MyEJB {
>
> @Context
> private UriInfo uriInfo;
>
> @GET
> @Path("{id}")
> public String displayMsg(@PathParam("id") Long id) {
> return "You've found id number " + id;
> }
> }
>
> This simple code will not wok and I'll get a : Exception
> creating stateless session bean : [MyEJB] with the following
> stack trace :
>
> A system exception occurred during an invocation on EJB
> MyEJB method public java.lang.String
> org.agoncal.example.MyEJB.displayMsg(java.lang.Long)
> javax.ejb.EJBException: javax.ejb.EJBException:
> javax.ejb.CreateException: Could not create stateless EJB at
> com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:454)
> at
> com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2528)
> at
> com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1895)
> at
> com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
> at
> com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
> at $Proxy137.displayMsg(Unknown Source) at
> org.agoncal.example.__EJB31_Generated__MyEJB__Intf____Bean__.displayMsg(Unknown
> Source) at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
> Source) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> Source) at java.lang.reflect.Method.invoke(Unknown
> Source) at
> org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305)
> at
> org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54)
> at
> org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163)
> at
> org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299)
> at
> org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:125)
> at
> org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62)
> at
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125)
> at org.agoncal.example.org <http://org.agoncal.example.org>
> <http://org.agoncal.example.org>$jboss$weld$bean-example-SessionBean-MyEJBorg$agoncal$example$MyEJB$@javax$ejb$Stateless(description=,mappedName=,name=)@javax$ws$rs$Path(value=$msg)${org$agoncal$example$MyEJB$uriInfo$@javax$inject$Inject()@javax$ws$rs$core$Context()$$org$agoncal$example$MyEJB$displayMsg$@javax$ws$rs$GET()@javax$ws$rs$Path(value={id})$(java$lang$Long$@javax$ws$rs$PathParam(value=id)$)$}_$$_WeldProxy.displayMsg(org$jboss$weld$bean-example-SessionBean-MyEJBorg$agoncal$example$MyEJB$@javax$ejb$Stateless(description=,mappedName=,name=)@javax$ws$rs$Path(value=$msg)${org$agoncal$example$MyEJB$uriInfo$@javax$inject$Inject()@javax$ws$rs$core$Context()$$org$agoncal$example$MyEJB$displayMsg$@javax$ws$rs$GET()@javax$ws$rs$Path(value={id})$(java$lang$Long$@javax$ws$rs$PathParam(value=id)$)$}_$$_WeldProxy.java)
> at
> org.agoncal.example.MyController.initList(MyController.java:31)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke0(Native
> Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown
> Source) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown
> Source) at java.lang.reflect.Method.invoke(Unknown
> Source) at
> org.glassfish.faces.integration.GlassFishInjectionProvider$2.run(GlassFishInjectionProvider.java:382)
> at
> java.security.AccessController.doPrivileged(Native Method) at
> org.glassfish.faces.integration.GlassFishInjectionProvider.invokeLifecycleMethod(GlassFishInjectionProvider.java:376)
> at
> org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:306)
> at
> org.glassfish.faces.integration.GlassFishInjectionProvider.invokePostConstruct(GlassFishInjectionProvider.java:229)
> at
> com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:223)
> at
> com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
> at
> com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
> at
> com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
> at
> com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
> at
> com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
> at
> com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
> at
> com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
> at
> com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:99)
> at
> com.sun.el.parser.AstValue.getValue(AstValue.java:158) at
> com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
> at
> org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:55)
> at
> com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
> at
> javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
> at
> javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182)
> at
> javax.faces.component.UIOutput.getValue(UIOutput.java:169) at
> com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
> at
> com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355)
> at
> com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
> at
> javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
> at
> com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312)
> at
> com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
> at
> com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129)
> at
> javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
> at
> javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
> at
> javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
> at
> javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
> at
> com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
> at
> com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
> at
> javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
> at
> com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
> at
> com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at
> com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
> at
> javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
> at
> org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
> at
> org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
> at
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
> at
> com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
> at
> com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
> at
> org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
> at
> com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
> at
> com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
> at
> com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
> at
> com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
> at
> com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
> at
> com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
> at
> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
> at
> com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
> at
> com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
> at
> com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
> at
> com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
> at
> com.sun.grizzly.ContextTask.run(ContextTask.java:71) at
> com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
> at
> com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
> at java.lang.Thread.run(Unknown Source)
> Caused by: javax.ejb.EJBException:
> javax.ejb.CreateException: Could not create stateless EJB at
> com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:726)
> at
> com.sun.ejb.containers.util.pool.NonBlockingPool.getObject(NonBlockingPool.java:247)
> at
> com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:449)
> ... 87 more Caused by:
> javax.ejb.CreateException: Could not create stateless EJB at
> com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:534)
> at
> com.sun.ejb.containers.StatelessSessionContainer.access$000(StatelessSessionContainer.java:95)
> at
> com.sun.ejb.containers.StatelessSessionContainer$SessionContextFactory.create(StatelessSessionContainer.java:724)
> ... 89
> more Caused by: java.lang.NullPointerException at
> com.sun.jersey.server.impl.cdi.CDIExtension$PredefinedBean.create(CDIExtension.java:927)
> at
> org.jboss.weld.context.unbound.DependentContextImpl.get(DependentContextImpl.java:67)
> at
> org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:690)
> at
> org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:772)
> at
> org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:138)
> at
> org.jboss.weld.util.Beans.injectBoundFields(Beans.java:872) at
> org.jboss.weld.util.Beans.injectFieldsAndInitializers(Beans.java:884)
> at
> org.jboss.weld.bean.SessionBean$1$1.proceed(SessionBean.java:195)
> at
> org.glassfish.weld.services.InjectionServicesImpl.aroundInject(InjectionServicesImpl.java:134)
> at
> org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:50)
> at
> org.jboss.weld.bean.SessionBean$1.inject(SessionBean.java:190)
> at
> org.glassfish.weld.services.JCDIServiceImpl.injectEJBInstance(JCDIServiceImpl.java:223)
> at
> com.sun.ejb.containers.BaseContainer.injectEjbInstance(BaseContainer.java:1675)
> at
> com.sun.ejb.containers.StatelessSessionContainer.createStatelessEJB(StatelessSessionContainer.java:494)
> ... 91 more
>
>
> But if I take the @Context private UriInfo uriInfo out, it
> works. I've reproduced this behavior on GF 3.1.1-b12 and GF
> 3.1.2-b03.
>
> Do you know why @Context UriInfo makes this kind of error ?
>
> Thanks,
> Antonio
>
> PS : I've sent this email to both users_at_glassfish.java.net
> <mailto:users_at_glassfish.java.net><mailto:users_at_glassfish.java.net
> <mailto:users_at_glassfish.java.net>>
> and users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net><mailto:users_at_glassfish.dev.java.net
> <mailto:users_at_glassfish.dev.java.net>> as I don't know if
> both are the same
>
>
>
>
> --
> --
> Antonio Goncalves (antonio.goncalves_at_gmail.com
> <mailto:antonio.goncalves_at_gmail.com>)
> Software architect
>
> Web site : www.antoniogoncalves.org <http://www.antoniogoncalves.org>
> Blog: agoncal.wordpress.com <http://agoncal.wordpress.com>
> Feed: feeds2.feedburner.com/AntonioGoncalves
> <http://feeds2.feedburner.com/AntonioGoncalves>
> Paris JUG leader : www.parisjug.org <http://www.parisjug.org>
> LinkedIn: www.linkedin.com/in/agoncal <http://www.linkedin.com/in/agoncal>