glassfish
  1. glassfish
  2. GLASSFISH-19251

SessionScoped managed bean can't be injected in to stateless session bean in EAR application with WAR (WELD-001303)

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 3.1.2.2
    • Fix Version/s: 4.0
    • Component/s: cdi
    • Labels:
      None
    • Environment:

      JDK 1.6.0_16, Windows Vista SP2 (32-bit)

      Description

      I have created an EAR application with following structure:

      testcase-ear-1.0-SNAPSHOT.ear
        - lib/testcase-api-1.0-SNAPSHOT.jar
            - testcase/LoginEJBLocal.class    (Local business interface)
        - META-INF/application.xml
        - testcase-ejb-1.0-SNAPSHOT.jar
            - META-INF/beans.xml
            - testcase/LoginBean.class        (Managed bean with SessionScoped)
            - testcase/LoginEJBBean.class     (Stateless session bean)
        - testcase-web-1.0-SNAPSHOT.war
            - WEB-INF/classes
                - testcase/SessionServlet.class      (WebServlet)
            - WEB-INF/lib/testcase-api-1.0-SNAPSHOT.jar
                - testcase/LoginEJBLocal.class       (Local business interface)
      

      Web servlet (SessionServlet) injects stateless session bean (LoginEJBBean) using local interface (LoginEJBLocal) and the bean should inject managed bean (LoginBean). But managed bean can't be injected because any active contexts for scope type SessionScoped can't be found. Following exception is thrown on http request:

      WARNING|glassfish3.1.2|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=23;_ThreadName=Thread-2;|javax.ejb.EJBException
      	at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5215)
      	at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5113)
      	at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
      	at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
      	at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
      	at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
      	at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:89)
      	at $Proxy535.getCurrentUser(Unknown Source)
      	at testcase.SessionServlet.doGet(SessionServlet.java:22)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
      	at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
      	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 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
      	at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
      	at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
      	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
      	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
      	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
      	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
      	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
      	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(Thread.java:619)
      Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
      	at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:619)
      	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
      	at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
      	at testcase.LoginBean$Proxy$_$$_WeldClientProxy.getCurrentUser(LoginBean$Proxy$_$$_WeldClientProxy.java)
      	at testcase.LoginEJBBean.getCurrentUser(LoginEJBBean.java:24)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
      	at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
      	at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
      	at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
      	at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
      	at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
      	at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:49)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
      	at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
      	at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
      	at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
      	at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      	at java.lang.reflect.Method.invoke(Method.java:597)
      	at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
      	at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
      	at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
      	at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
      	at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
      	at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
      	... 29 more
      

      In attachment your can find source code and EJB application.
      Here are my classes:

      LoginEJBLocal.java
      @Local
      public interface LoginEJBLocal {
          void login(String user);
          void logout();
          String getCurrentUser();
      }
      
      LoginEJBBean.java
      @Stateless
      public class LoginEJBBean implements LoginEJBLocal {
          @Inject
          private LoginBean loginBean;
          @Override
          public void login(String user) {
              loginBean.login(user);
          }
          @Override
          public void logout() {
              loginBean.logout();
          }
          @Override
          public String getCurrentUser() {
              return loginBean.getCurrentUser();
          }
      }
      
      LoginBean.java
      @SessionScoped
      public class LoginBean implements Serializable {
          private String user;
          public void login(String user) {
              this.user = user;
          }
          public void logout() {
              this.user = null;
          }
          public String getCurrentUser() {
              return user;
          }
      }
      
      SessionServlet.java
      @WebServlet("/sesser")
      public class SessionServlet extends HttpServlet {
          @EJB
          private LoginEJBLocal loginBean;
          @Override
          protected void doGet(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
              System.out.println("GET request");
              String user = loginBean.getCurrentUser();
              if (user != null) {
                  System.out.println("Hello, " + user + "!");
              } else {
                  System.out.println("Hello! Who are you?");
                  loginBean.login("user-" + new Date());
              }
          }
      }
      

        Activity

          People

          • Assignee:
            jjsnyder83
            Reporter:
            Volodja Medvid
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: