Issue Details (XML | Word | Printable)

Key: GLASSFISH-19251
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: jjsnyder83
Reporter: Volodja Medvid
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
glassfish

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

Created: 26/Oct/12 01:23 PM   Updated: 27/Nov/13 09:15 PM   Resolved: 26/Apr/13 08:11 PM
Component/s: cdi
Affects Version/s: 3.1.2.2
Fix Version/s: 4.0

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive testcase.zip (15 kB) 26/Oct/12 01:23 PM - Volodja Medvid

Environment:

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


Tags: cdi weld 4_0-approved
Participants: arjavdesai, jjsnyder83, shreedhar_ganapathy, Volodja Medvid and ymajoros


 Description  « Hide

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());
        }
    }
}


tlcksnyder made changes - 14/Feb/13 03:45 PM
Field Original Value New Value
Fix Version/s 4.0 [ 10970 ]
tlcksnyder made changes - 05/Mar/13 08:29 PM
Assignee jjsnyder83 [ jjsnyder83 ] arjavdesai [ arjavdesai ]
arjavdesai made changes - 25/Mar/13 07:04 PM
Assignee arjavdesai [ arjavdesai ] jjsnyder83 [ jjsnyder83 ]
shreedhar_ganapathy added a comment - 19/Apr/13 03:42 PM

Any further root cause analysis on this issue?
Could you please provide the ETA for the fix?
GF 4.0 RC testing is starting and we need fixes to go in ASAP.


jjsnyder83 added a comment - 26/Apr/13 07:50 PM

What is the impact on the customer of the bug?
CDI doesn't work for some ejb apps

How likely is it that a customer will see the bug and how serious is the bug?
Is it a regression? Does it meet other bug fix criteria (security, performance, etc.)?
What CTS failures are caused by this bug?
very

What is the cost/risk of fixing the bug?
N/A

How risky is the fix? How much work is the fix? Is the fix complicated?
N/A

Is there an impact on documentation or message strings?
No

Which tests should QA (re)run to verify the fix did not destabilize GlassFish?
CDI TCK

Which is the targeted build of 4.0 for this fix?
4.0_b86_RC2

If this an integration of a new version of a component from another project,
what are the changes that are being brought in? This might be list of
Jira issues from that project or a list of revision messages.
N/A


jjsnyder83 made changes - 26/Apr/13 07:51 PM
Tags cdi weld cdi weld 4_0-review
michael.y.chen made changes - 26/Apr/13 08:07 PM
Tags cdi weld 4_0-review cdi weld 4_0-approved
jjsnyder83 added a comment - 26/Apr/13 08:11 PM

Committed revision 61689.


jjsnyder83 made changes - 26/Apr/13 08:11 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
ymajoros added a comment - 27/Nov/13 09:15 PM

So, for anyone looking for a workaround for it for glassfish 3, the solution is as easy as activating weld in the war that calls the ejb that calls the SessionScoped bean. Just add a beans.xml and it works.

Simply found out from the patch: https://java.net/projects/glassfish/sources/svn/revision/61689