1 2 Previous Next 17 Replies Latest reply on Apr 17, 2011 6:41 AM by arjan tijms

    Problems with stateless beans in Weld CR 1.0.1 CR2

    Andy Gibson Novice

      I've had a problem with JBoss AS 6.0 M1 and 2 and with Weld 1.0.1 CR 1 and 2.


      New project, create a JSF page referencing a bean which has a method that returns a string :


      <h:form>
      Message : <h:outputText value="#{messageBean.message}" />
      </h:form>
      



      and


      @Named
      public class MessageBean implements Serializable {
      
           public String getMessage() {
                return "This is my messages";
           }
      }
      



      And everything works fine.  However, annotate the CDI bean as stateless and you have problems. I'm packaging this as a war, and deploying to the JBoss 6 M2 released just yesterday with Weld 1.0.1 CR1. The stateless bean is being discovered as per the log but I get an NPE when I try to access it.


      I exported a war file and ran it on Glassfish with no problems (build 74.2 - I think Weld 1.0).


      I upgraded JBoss to use Weld 1.0.1 CR 2 and tried it again. The log confirms the weld version and the discovery of the bean :


      INFO  [org.jboss.ejb3.EJBContainer] STARTED EJB: org.cdiapp.MessageBean ejbName: MessageBean
      INFO  [org.jboss.ejb3.proxy.impl.jndiregistrar.JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
      
      
      INFO  [org.jboss.weld.Version] WELD-000900 1.0.1 (CR2)
      INFO  [org.jboss.ejb3.nointerface.impl.jndi.AbstractNoInterfaceViewJNDIBinder] Binding the following entry in Global JNDI:
      
           MessageBean/no-interface - EJB3.1 no-interface view
      
      



      Ran it again, and got a more helpful exception :


      
      javax.servlet.ServletException: WELD-000079 Could not find the EJB in JNDI:  class org.cdiapp.MessageBean_$$_javassist_63
           javax.faces.webapp.FacesServlet.service(FacesServlet.java:325)
           org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:66)
      
      root cause
      
      org.jboss.weld.exceptions.CreationException: WELD-000079 Could not find the EJB in JNDI:  class org.cdiapp.MessageBean_$$_javassist_63
           org.jboss.weld.bean.SessionBean.create(SessionBean.java:313)
           org.jboss.weld.context.AbstractMapContext.get(AbstractMapContext.java:112)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:142)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:99)
           org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
           org.cdiapp.MessageBean_$$_javassist_69.getMessage(MessageBean_$$_javassist_69.java)
           sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           java.lang.reflect.Method.invoke(Method.java:597)
           javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
           javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
           com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
           org.apache.el.parser.AstValue.getValue(AstValue.java:134)
           org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
           org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:71)
           com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
           javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
           javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
           javax.faces.component.UIOutput.getValue(UIOutput.java:168)
           com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
           com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:338)
           com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
           javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
           javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
           javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
           javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
           javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
           javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
           com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
           com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
           javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
           com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
           com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
           com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
           org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:66)
      
      root cause
      
      java.lang.IllegalArgumentException: not a proxy instance
           java.lang.reflect.Proxy.getInvocationHandler(Proxy.java:637)
           org.jboss.weld.integration.ejb.JBossSessionObjectReference.<init>(JBossSessionObjectReference.java:44)
           org.jboss.weld.integration.ejb.JBossEjbServices.resolveEjb(JBossEjbServices.java:112)
           org.jboss.weld.bean.SessionBean.createReference(SessionBean.java:411)
           org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.<init>(EnterpriseBeanProxyMethodHandler.java:76)
           org.jboss.weld.bean.SessionBean.create(SessionBean.java:296)
           org.jboss.weld.context.AbstractMapContext.get(AbstractMapContext.java:112)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.getProxiedInstance(ClientProxyMethodHandler.java:142)
           org.jboss.weld.bean.proxy.ClientProxyMethodHandler.invoke(ClientProxyMethodHandler.java:99)
           org.jboss.weld.util.CleanableMethodHandler.invoke(CleanableMethodHandler.java:43)
           org.cdiapp.MessageBean_$$_javassist_69.getMessage(MessageBean_$$_javassist_69.java)
           sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           java.lang.reflect.Method.invoke(Method.java:597)
           javax.el.BeanELResolver.getValue(BeanELResolver.java:302)
           javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
           com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
           org.apache.el.parser.AstValue.getValue(AstValue.java:134)
           org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
           org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:71)
           com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
           javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
           javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
           javax.faces.component.UIOutput.getValue(UIOutput.java:168)
           com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
           com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:338)
           com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
           javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
           javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
           javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
           javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
           javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
           javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
           com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
           com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
           javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
           com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
           com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
           com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
           javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
           org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:66)
      



      It seems JBoss 6 M2 lets you deploy EJBs in WAR files (YAY!) but I tried it with an Ear anyway and it still fails. It seems a little weird that the whole stateless bean would fail in weld in such a simple case, so I'm not sure I'm missing something. My app was built as an eclipse dynamic web project with JBoss Tools Nightly (and using their build drivers). I created the project and added the JSF and CDI facet and tweaked the generated faces-config.xml to use JSF 2.0 instead of the default 1.2. Again, it works fine as a non-ejb CDI bean. Changing it to be a Stateful also results in the same problem.


      Cheers,


      Andy

        1 2 Previous Next