0 Replies Latest reply on Dec 9, 2014 8:10 AM by Robert Herschke

    Websockets and Stateful Session Beans

    Robert Herschke Newbie

      I think, there is a problem in Wildfly (8.2.0.Final) regarding Websockets and Stateful Session Beans.

       

      This is the simple usecase:

       

      @ServerEndpoint("...") 
      public class WebSocketEndpoint {
         @EJB
         MySFSB bean;
       
         @OnOpen
         public void onOpen() {
           bean.open();   
         }
         ...  
      
        @OnClose
         public void onClose() {
           bean.close();
         }
       }
      
      @Stateful 
      public class MySFSB {
           public void open() {     // ...   }
      
         @Remove
         public void close() {    // ...   } 
      } 
      

      The expected behavior is: (it is so in Tomee 1.7.1 and Glassfish 4.x)

      • A browser opens a websocket to that endpoint so the onOpen() is called and a NEW instance (since a new client is connected) of MySFSB is created.
      • When the browser sends the disconnect event, the onClose() is called, delegating to the close()-Method of MySFSB and removes the instance of the MySFSB.
      • When the (same) browser reconnects (due to a refresh of the page) to the websocket, then again a NEW instance of MySFSB is created.
      • and so on.

       

      The actual behavior is:

      • A browser opens a websocket to that endpoint so the onOpen() is called and a NEW instance (since a new client is connected) of MySFSB is created.
      • When the browser sends the disconnect event, the onClose() is called, delegating to the close()-Method of MySFSB and removes the instance of the MySFSB.
      • After a reconnect (browser reloads the page) the websocket tries to inject the same instance of MySFSB which cannot be found. An exception (see below) raises.
      • Even another browser instance does not bring Wildfly to instantiate another instance of MySFSB. The WebSocket-Endpoint ALWAYS get the same MySFSB instance for each new WebSocket-Session! This might be wrong!

       

      The exception:

      14:02:36,110 ERROR [io.undertow.websockets.core.request] (default task-1) UT025007: Unhandled exception for annotated endpoint Proxy for view class: com.example.WebsocketEndpoint of EJB: WebSocketEndpoint: javax.ejb.NoSuchEJBException: JBAS014300: Could not find EJB with id {[44, 16, 124, 127, -60, -96, 79, 73, -72, 36, -80, 17, 69, 5, -113, -99]}
           at org.jboss.as.ejb3.component.stateful.StatefulComponentInstanceInterceptor.processInvocation(StatefulComponentInstanceInterceptor.java:62) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInNoTx(CMTTxInterceptor.java:260) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.as.ejb3.tx.CMTTxInterceptor.notSupported(CMTTxInterceptor.java:319) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:237) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
           at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:439)
           at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
           at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
           at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185)
           at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
           at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73)
           at com.example.MySFSB$$$view135.open(Unknown Source) [classes:]
           at com.example.WebsocketEndpoint.onOpen(WebsocketEndpoint.java:5) [classes:]
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_25]
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_25]
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_25]
           at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_25]
           at org.jboss.as.ee.component.ManagedReferenceMethodInterceptor.processInvocation(ManagedReferenceMethodInterceptor.java:52)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
           at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
           at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doMethodInterception(Jsr299BindingsInterceptor.java:82) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:93) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53)
           at org.jboss.as.ee.component.interceptors.UserInterceptorFactory$1.processInvocation(UserInterceptorFactory.java:63)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.invocationmetrics.ExecutionTimeInterceptor.processInvocation(ExecutionTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
           at org.jboss.as.ejb3.concurrency.ContainerManagedConcurrencyInterceptor.processInvocation(ContainerManagedConcurrencyInterceptor.java:104) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407)
           at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55) [weld-core-impl-2.2.6.Final.jar:2014-10-03 10:05]
           at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83) [wildfly-weld-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45) [wildfly-ee-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InitialInterceptor.processInvocation(InitialInterceptor.java:21)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
           at org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor.processInvocation(ComponentDispatcherInterceptor.java:53)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.singleton.SingletonComponentInstanceAssociationInterceptor.processInvocation(SingletonComponentInstanceAssociationInterceptor.java:52) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:340) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
           at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:448)
           at org.jboss.invocation.AccessCheckingInterceptor.processInvocation(AccessCheckingInterceptor.java:61)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326)
           at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
           at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:185)
           at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182)
           at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
           at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61)
           at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:73)
           at com.example.WebsocketEndpoint$$$view134.onOpen(Unknown Source) [classes:]
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.8.0_25]
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [rt.jar:1.8.0_25]
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.8.0_25]
           at java.lang.reflect.Method.invoke(Method.java:483) [rt.jar:1.8.0_25]
           at io.undertow.websockets.jsr.annotated.BoundMethod.invoke(BoundMethod.java:87) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2$1.run(AnnotatedEndpoint.java:154) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:362) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at io.undertow.websockets.jsr.annotated.AnnotatedEndpoint$2.onMessage(AnnotatedEndpoint.java:149) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at io.undertow.websockets.jsr.FrameHandler$7.run(FrameHandler.java:247) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at io.undertow.websockets.jsr.ServerWebSocketContainer.invokeEndpointMethod(ServerWebSocketContainer.java:362) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at io.undertow.websockets.jsr.ServerWebSocketContainer$3.run(ServerWebSocketContainer.java:347) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at io.undertow.websockets.jsr.OrderedExecutor$ExecutorTask.run(OrderedExecutor.java:67) [undertow-websockets-jsr-1.1.0.Final.jar:1.1.0.Final]
           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
           at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
      

       

      Do I have to file a bug-ticket for this?

       

      Is there a workaround to have an instance of a Stateful-Session Bean for each Websocket-Session?

       

      Thanks a lot,

      Robert