3 Replies Latest reply on Jan 19, 2017 10:24 AM by Tom Eicher

    Using Websockets in an ejb project

    Sueleyman Vurucu Expert

      Hi guys,

       

      I have a ear project with the structure shown below:

       

      EAR

      +---lib

      +---war-module

      +---ejb-module1

      +---ejb-module2

       

      I try to buil a websocketconnection in my EJB project but I got the expetion shown below.

      11:05:02,106 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 2) MSC000001: Failed to start service jboss.deployment.subunit."wms-wan.ear"."wms-base-controller-3.0.0-SNAPSHOT.jar".component.WebsocketTest.START: org.jboss.msc.service.StartException in service jboss.deployment.subunit."wms-wan.ear"."wms-base-controller-3.0.0-SNAPSHOT.jar".component.WebsocketTest.START: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
          at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:57)
          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) [rt.jar:1.7.0_25]
          at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [rt.jar:1.7.0_25]
          at java.util.concurrent.FutureTask.run(FutureTask.java:166) [rt.jar:1.7.0_25]
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_25]
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_25]
          at java.lang.Thread.run(Thread.java:724) [rt.jar:1.7.0_25]
          at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.1.1.Final.jar:2.1.1.Final]
      Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance
          at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:162)
          at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:133)
          at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:89)
          at org.jboss.as.ejb3.component.singleton.SingletonComponent.getComponentInstance(SingletonComponent.java:122)
          at org.jboss.as.ejb3.component.singleton.SingletonComponent.start(SingletonComponent.java:137)
          at org.jboss.as.ee.component.ComponentStartService$1.run(ComponentStartService.java:54)
          ... 7 more
      Caused by: javax.ejb.EJBException: java.lang.RuntimeException: Cannot load platform configurator
          at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190)
          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275)
          at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:369)
          at org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor.processInvocation(LifecycleCMTTxInterceptor.java:66)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.weld.injection.WeldInjectionContextInterceptor.processInvocation(WeldInjectionContextInterceptor.java:43)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.ee.concurrent.ConcurrentContextInterceptor.processInvocation(ConcurrentContextInterceptor.java:45)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.ContextClassLoaderInterceptor.processInvocation(ContextClassLoaderInterceptor.java:64) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.InterceptorContext.run(InterceptorContext.java:326) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.PrivilegedWithCombinerInterceptor.processInvocation(PrivilegedWithCombinerInterceptor.java:80) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:160)
          ... 12 more
      Caused by: java.lang.RuntimeException: Cannot load platform configurator
          at javax.websocket.server.ServerEndpointConfig$Configurator.fetchContainerDefaultConfigurator(ServerEndpointConfig.java:123)
          at javax.websocket.server.DefaultServerEndpointConfig.<init>(DefaultServerEndpointConfig.java:85)
          at javax.websocket.server.ServerEndpointConfig$Builder.build(ServerEndpointConfig.java:301)
          at com.siemag.server.WebsocketTest.init(WebsocketTest.java:57)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_25]
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_25]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_25]
          at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_25]
          at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptor.java:96)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.doLifecycleInterception(Jsr299BindingsInterceptor.java:114)
          at org.jboss.as.weld.ejb.Jsr299BindingsInterceptor.processInvocation(Jsr299BindingsInterceptor.java:103)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:407) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:55)
          at org.jboss.as.weld.ejb.EjbRequestScopeActivationInterceptor.processInvocation(EjbRequestScopeActivationInterceptor.java:83)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.weld.injection.WeldInjectionInterceptor.processInvocation(WeldInjectionInterceptor.java:53)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.ee.component.AroundConstructInterceptorFactory$1.processInvocation(AroundConstructInterceptorFactory.java:28)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.weld.injection.WeldInterceptorInjectionInterceptor.processInvocation(WeldInterceptorInjectionInterceptor.java:56)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.weld.ejb.Jsr299BindingsCreateInterceptor.processInvocation(Jsr299BindingsCreateInterceptor.java:94)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50)
          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309) [jboss-invocation-1.2.1.Final.jar:1.2.1.Final]
          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:273)
          ... 30 more
      
      

       

      On the other hand. If I move my singleton EJB bean to the war project then everything works well.

      @Singleton
      @LocalBean
      @Startup
      public class WebsocketTest {
          @Inject
          private Logger logger;
      
      
          public class EchoEndpoint extends Endpoint {
      
              @Override
              public void onOpen(final Session session, EndpointConfig config) {
                  session.addMessageHandler(new MessageHandler.Whole<String>() {
                      @Override
                      public void onMessage(String msg) {
                          try {
                              session.getBasicRemote().sendText(msg);
                          } catch (IOException e) {
                              e.printStackTrace();
                          }
                      }
                  });
              }
      
              @Override
              public void onClose(Session session, CloseReason closeReason) {
                  System.err.println("Close");
              }
      
              @Override
              public void onError(Session session, Throwable thr) {
                  System.err.println("ERROR");
                  thr.printStackTrace();
              }
          }
      
          @PostConstruct
          private void init() {
              ServerEndpointConfig.Builder.create(EchoEndpoint.class, "/echo").build();
              System.err.println("Endpoint OK");
          }
      
      }
      
      

       

       

      Is there a limitation that I can use websockets only in war projects?