Search code examples
websocketembedded-jettyjetty-9jsr356

Websocket JSR-356 fail with Jetty 9.4.1


My current web server is embedded Jetty 9.1.5. It works well with JSR-356 to create websocket. These days, I am trying to upgrade to Jetty 9.4.1. Everything works nicely except websocket.
My code like below:

  1. Embedded Jetty and Websocket libs:
<dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-server</artifactId>
   <version>9.4.1.v20170120</version>
</dependency>
<dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-webapp</artifactId>
   <version>9.4.1.v20170120</version>
</dependency>
<dependency>
   <groupId>org.eclipse.jetty</groupId>
   <artifactId>jetty-annotations</artifactId>
   <version>9.4.1.v20170120</version>
</dependency>
<dependency>
   <groupId>org.eclipse.jetty.websocket</groupId>
   <artifactId>javax-websocket-server-impl</artifactId>
   <version>9.4.1.v20170120</version>
</dependency>
  1. Server endpoint:
  @ServerEndpoint(value = "/ws/communication/{officeId}/{username}/{oldWSSession}")
  class WSCommunication {
     // @OnOpen, @OnMessage, @OnClose methods
  }
  1. Jetty server, Webapp context, Websocket configuration:

      // Jetty server
      Server server = new Server();
      String[] configFiles = {"./etc/jetty.xml"};
      for (String configFile : configFiles) {
         XmlConfiguration configuration = new XmlConfiguration(new File(configFile).toURI().toURL());
         configuration.configure(server);
    
         Connector[] connectors =  server.getConnectors();
         if (connectors != null && connectors.length == 2) {
            ServerConnector serverConnector = (ServerConnector) connectors[1];
            serverConnector.setPort(8443);
         }
       }
    
       // Webapp context
       WebAppContext webContext = new WebAppContext(ResourceManager.getWebappsPath(), "/myContext");
       webContext.setContextPath("/myContext");
       webContext.setResourceBase(ResourceManager.getWebappsPath() + contextPath);
       webContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
    
       private List<WebAppContext> listWebContext = new ArrayList<>();
       listWebContext.add(webContext);
    
       ContextHandlerCollection contexts = new ContextHandlerCollection();
       contexts.setHandlers(listWebContext.toArray(new WebAppContext[listWebContext.size()]));
       server.setHandler(contexts);
    
       // Start server
       server.start();
    
       // Websocket
       ServerContainer container =
       WebSocketServerContainerInitializer.configureContext(webContext);
       container.addEndpoint(webContext.getClassLoader().loadClass(
                             "com.example.WSCommunication"));
    
       container.setDefaultMaxSessionIdleTimeout(84600);
    
       // Dump server log
       server.dumpStdErr();
    
  2. Dump:

     org.eclipse.jetty.server.Server@5ca13457 - STARTED
           += qtp348159759{STARTED,10<=19<=200,i=1,q=0} - STARTED
           |   +- 30 qtp348159759-30 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 31 qtp348159759-31-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- 89 qtp348159759-89-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- 85 qtp348159759-85-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- 33 qtp348159759-33-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- 36 qtp348159759-36 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 35 qtp348159759-35-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- 90 qtp348159759-90-acceptor-0@6a934d20-ServerConnector@31de14e{SSL,[ssl, http/1.1]}{0.0.0.0:8443} RUNNABLE @ sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method) prio=3
           |   +- 84 qtp348159759-84 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 86 qtp348159759-86 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 38 qtp348159759-38-acceptor-0@21398b5e-ServerConnector@52bab8e{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} RUNNABLE @ sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method) prio=3
           |   +- 87 qtp348159759-87-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- 92 qtp348159759-92 TIMED_WAITING @ sun.misc.Unsafe.park(Native Method) IDLE
           |   +- 32 qtp348159759-32 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 34 qtp348159759-34 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 88 qtp348159759-88 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 39 qtp348159759-39 RUNNABLE @ sun.nio.ch.KQueueArrayWrapper.kevent0(Native Method)
      |   +- 37 qtp348159759-37-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- 83 qtp348159759-83-lowPrioritySelector BLOCKED @ org.eclipse.jetty.io.ManagedSelector$SelectorProducer.produce(ManagedSelector.java:244) prio=1
           |   +- jobs
           += org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@1ca4b0fd - STARTED
           |   +- sun.misc.Unsafe.park(Native Method)
           |   +- java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
           |   +- java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
           |   +- java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
           |   +- java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
           |   +- java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
           |   +- java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
           |   +- java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
           |   +- java.lang.Thread.run(Thread.java:745)
           += ServerConnector@52bab8e{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} - STARTED
           |   +~ org.eclipse.jetty.server.Server@5ca13457 - STARTED
           |   +~ qtp348159759{STARTED,10<=19<=200,i=1,q=0} - STARTED
           |   +~ org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@1ca4b0fd - STARTED
           |   +- org.eclipse.jetty.io.ArrayByteBufferPool@4f751fc9
           |   += HttpConnectionFactory@30bf9c09[HTTP/1.1] - STARTED
           |   |   +- HttpConfiguration@248e9950{32768/8192,8192/8192,https://:8443,[]}
           |   += org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@282048ea - STARTED
           |   |   += org.eclipse.jetty.io.ManagedSelector@65c05e53 id=0 keys=0 selected=0 id=0
           |   |   |   +- sun.nio.ch.KQueueSelectorImpl@6724bccb keys=0
           |   |   += org.eclipse.jetty.io.ManagedSelector@1fa04d47 id=1 keys=0 selected=0 id=1
           |   |   |   +- sun.nio.ch.KQueueSelectorImpl@5fcb5753 keys=0
           |   |   += org.eclipse.jetty.io.ManagedSelector@7999a7f0 id=2 keys=0 selected=0 id=2
           |   |   |   +- sun.nio.ch.KQueueSelectorImpl@3abe8266 keys=0
           |   |   += org.eclipse.jetty.io.ManagedSelector@6d2e80a1 id=3 keys=0 selected=0 id=3
           |   |       +- sun.nio.ch.KQueueSelectorImpl@2e5f2aae keys=0
           |   +- sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:8080]
           |   +- qtp348159759-38-acceptor-0@21398b5e-ServerConnector@52bab8e{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
           += ServerConnector@31de14e{SSL,[ssl, http/1.1]}{0.0.0.0:8443} - STARTED
           |   +~ org.eclipse.jetty.server.Server@5ca13457 - STARTED
           |   +~ qtp348159759{STARTED,10<=20<=200,i=2,q=0} - STARTED
           |   +~ org.eclipse.jetty.util.thread.ScheduledExecutorScheduler@1ca4b0fd - STARTED
           |   +- org.eclipse.jetty.io.ArrayByteBufferPool@3838889e
           |   += SslConnectionFactory@7b040213{SSL->http/1.1} - STARTED
           |   |   += SslContextFactory@a3ac71d(file:///workspace/myApp/myApp-server/webapps/conf/iDS.keystore,null) trustAll=false
           |   |       +- Protocol Selections
           |   |       |   +- Enabled (size=3)
           |   |       |   |   +- TLSv1
           |   |       |   |   +- TLSv1.1
           |   |       |   |   +- TLSv1.2
           |   |       |   +- Disabled (size=2)
           |   |       |       +- SSLv2Hello - ConfigExcluded:'SSLv2Hello'
           |   |       |       +- SSLv3 - JreDisabled:java.security, ConfigExcluded:'SSLv3'
           |   |       +- Cipher Suite Selections
           |   |           +- Enabled (size=43)
           |   |           |   [CIPHERS]
           |   |           +- Disabled (size=39)
           |   |               [CIPHERS]
           |   += HttpConnectionFactory@116d58cf[HTTP/1.1] - STARTED
           |   |   +- HttpConfiguration@3ba7eaf0{32768/8192,8192/8192,https://:8443,[SecureRequestCustomizer@229efbd3]}
           |   += org.eclipse.jetty.server.ServerConnector$ServerConnectorManager@14690caf - STARTED
           |   |   += org.eclipse.jetty.io.ManagedSelector@e1ecb28 id=0 keys=0 selected=0 id=0
           |   |   |   +- sun.nio.ch.KQueueSelectorImpl@2edda3f6 keys=0
           |   |   += org.eclipse.jetty.io.ManagedSelector@aea4071 id=1 keys=0 selected=0 id=1
           |   |   |   +- sun.nio.ch.KQueueSelectorImpl@2482929a keys=0
           |   |   += org.eclipse.jetty.io.ManagedSelector@5fff729c id=2 keys=0 selected=0 id=2
           |   |   |   +- sun.nio.ch.KQueueSelectorImpl@7f0a5bb3 keys=0
           |   |   += org.eclipse.jetty.io.ManagedSelector@32f11b8 id=3 keys=0 selected=0 id=3
           |   |       +- sun.nio.ch.KQueueSelectorImpl@153f56b1 keys=0
           |   +- sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:8443]
           |   +- qtp348159759-90-acceptor-0@6a934d20-ServerConnector@31de14e{SSL,[ssl, http/1.1]}{0.0.0.0:8443}
           += org.eclipse.jetty.server.handler.ContextHandlerCollection@7b10dd7e[o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}, o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}] - STARTED
           |   += o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps} - STARTED
           |   |   += org.eclipse.jetty.server.session.SessionHandler589427621==dftMaxIdleSec=1800 - STARTED
           |   |   |   += org.eclipse.jetty.security.ConstraintSecurityHandler@76e1ecf - STARTED
           |   |   |   |   +- org.eclipse.jetty.security.DefaultAuthenticatorFactory@7cb77d4b
           |   |   |   |   += org.eclipse.jetty.servlet.ServletHandler@1b1b48e - STARTED
           |   |   |   |   |   += org.eclipse.jetty.servlet.ListenerHolder@2da1d3c6 - STARTED
           |   |   |   |   |   += org.eclipse.jetty.servlet.ListenerHolder@5ace38db - STARTED
           |   |   |   |   |   += default@5c13d641==org.eclipse.jetty.servlet.DefaultServlet,jsp=null,order=0,inst=true - STARTED
           |   |   |   |   |   |   +- aliases=false
           |   |   |   |   |   |   +- dirAllowed=true
           |   |   |   |   |   |   +- maxCacheSize=256000000
           |   |   |   |   |   |   +- maxCachedFileSize=200000000
           |   |   |   |   |   |   +- welcomeServlets=false
           |   |   |   |   |   |   +- useFileMappedBuffer=true
           |   |   |   |   |   |   +- acceptRanges=true
           |   |   |   |   |   |   +- etags=false
           |   |   |   |   |   |   +- maxCachedFiles=2048
           |   |   |   |   |   |   +- redirectWelcome=false
           |   |   |   |   |   += jsp@19c47==org.eclipse.jetty.jsp.JettyJspServlet,jsp=null,order=0,inst=true - STARTED
           |   |   |   |   |   |   +- fork=false
           |   |   |   |   |   |   +- compilerSourceVM=1.7
           |   |   |   |   |   |   +- logVerbosityLevel=DEBUG
           |   |   |   |   |   |   +- compilerTargetVM=1.7
           |   |   |   |   |   |   +- scratchdir=/private/var/folders/8p/f__1hb6j0p5bq7ljqdkjg35h0000gn/T/jetty-0.0.0.0-8080-myContext-_myContext-any-6227228818832412481.dir/jsp
           |   |   |   |   |   |   +- xpoweredBy=false
           |   |   |   |   |   +- [/]=>default
           |   |   |   |   |   +- [*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp
           |   |   |   |   |   += org.eclipse.jetty.servlet.ListenerHolder@1dd44bec - STARTED
           |   |   |   |   |   += org.eclipse.jetty.servlet.ListenerHolder@114d991c - STARTED
           |   |   |   |   |   += ISSSecurityFilter - STARTED
           |   |   |   |   |   += GzipFilter - STARTED
           |   |   |   |   |   |   +- mimeTypes=text/plain,text/html,text/css,application/javascript,application/x-javascript,application/json
           |   |   |   |   |   += Dashboard@38fd0a74==com.example.web.Dashboard,jsp=null,order=1,inst=true - STARTED
           |   |   |   |   |   |   +- parameter=value
           |   |   |   |   |   += idental-mvc@441f8928==org.springframework.web.servlet.DispatcherServlet,jsp=null,order=-1,inst=false - STARTED
           |   |   |   |   |   [SERVLET MAPPING]
           |   |   |   |   |   +~ Jetty_WebSocketUpgradeFilter - STARTED
           |   |   |   |   |   +- [/*]/[]==1=>Jetty_WebSocketUpgradeFilter
      |   |   |   |   |
      |   |   |   |   +> null
      |   |   |   |   +> null
      |   |   |   |   +> null
      |   |   |   |   +> []
      |   |   |   |   +> /*={*={RoleInfo[],Confidential}}
      |   |   |   |   +> /={TRACE={RoleInfo,F,C[],None}, TRACE.omission={RoleInfo[],None}}
      |   |   |   +~ com.example.web.ContextListener@32d15710
      |   |   |   += org.eclipse.jetty.server.session.DefaultSessionCache@19f2b971[evict=-1,removeUnloadable=false,saveOnCreate=false,saveOnInactiveEvict=false] - STARTED
      |   |   |   |   += org.eclipse.jetty.server.session.NullSessionDataStore@26c61a88[passivating=false,graceSec=3600] - STARTED
      |   |   |   +~ org.eclipse.jetty.server.session.DefaultSessionIdManager@5bbef235[worker=node0] - STARTED
      |   |   += org.eclipse.jetty.servlet.ErrorPageErrorHandler@636f4785 - STARTED
      |   |   +~ org.eclipse.jetty.websocket.jsr356.server.ServerContainer@6fda53a8 - STOPPED
      |   |   |
      |   |   +> WebAppClassLoader=myContext@27e16098
      |   |   |   [LIBS]
      |   |   |   +- sun.misc.Launcher$AppClassLoader@18b4aac2
      |   |   +> Systemclasses o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}
      |   |   |   +- java.
      |   |   |   +- javax.
      |   |   |   +- org.eclipse.jetty.continuation.
      |   |   |   +- org.eclipse.jetty.jaas.
      |   |   |   +- org.eclipse.jetty.jmx.
      |   |   |   +- org.eclipse.jetty.jndi.
      |   |   |   +- org.eclipse.jetty.jsp.JettyJspServlet
      |   |   |   +- org.eclipse.jetty.servlet.DefaultServlet
      |   |   |   +- org.eclipse.jetty.servlets.PushCacheFilter
      |   |   |   +- org.eclipse.jetty.servlets.PushSessionCacheFilter
      |   |   |   +- org.eclipse.jetty.util.annotation.
      |   |   |   +- org.eclipse.jetty.util.log.
      |   |   |   +- org.eclipse.jetty.websocket.
      |   |   |   +- org.w3c.
      |   |   |   +- org.xml.
      |   |   +> Serverclasses o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}
      |   |   |   +- -org.eclipse.jetty.alpn.
      |   |   |   +- -org.eclipse.jetty.apache.
      |   |   |   +- -org.eclipse.jetty.continuation.
      |   |   |   +- -org.eclipse.jetty.jaas.
      |   |   |   +- -org.eclipse.jetty.jmx.
      |   |   |   +- -org.eclipse.jetty.jndi.
      |   |   |   +- -org.eclipse.jetty.jsp.
      |   |   |   +- -org.eclipse.jetty.server.session.SessionData
      |   |   |   +- -org.eclipse.jetty.servlet.DefaultServlet
      |   |   |   +- -org.eclipse.jetty.servlet.NoJspServlet
      |   |   |   +- -org.eclipse.jetty.servlet.listener.
      |   |   |   +- -org.eclipse.jetty.servlets.
      |   |   |   +- -org.eclipse.jetty.util.annotation.
      |   |   |   +- -org.eclipse.jetty.util.log.
      |   |   |   +- -org.eclipse.jetty.websocket.
      |   |   |   +- org.eclipse.jdt.
      |   |   |   +- org.eclipse.jetty.
      |   |   |   +- org.objectweb.asm.
      |   |   +> Configurations o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}
      |   |   |   +- org.eclipse.jetty.webapp.WebInfConfiguration@795e1681
      |   |   |   +- org.eclipse.jetty.webapp.WebXmlConfiguration@55dd7cc5
      |   |   |   +- org.eclipse.jetty.webapp.MetaInfConfiguration@4c174a94
      |   |   |   +- org.eclipse.jetty.webapp.FragmentConfiguration@71ed07ad
      |   |   |   +- org.eclipse.jetty.webapp.JettyWebXmlConfiguration@780efd0f
      |   |   +> Handler attributes o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}
      |   |   |   +- javax.servlet.context.tempdir=/private/var/folders/8p/f__1hb6j0p5bq7ljqdkjg35h0000gn/T/jetty-0.0.0.0-8080-myContext-_myContext-any-6227228818832412481.dir
      |   |   |   +- org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.SCI=WebSocketUpgradeFilter[configuration=org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration@468b9d9f]
      |   |   |   +- org.eclipse.jetty.server.Executor=qtp348159759{STARTED,10<=20<=200,i=2,q=0}
      |   |   |   +- org.apache.catalina.jsp_classpath=[LIBS]
      |   |   |   +- javax.websocket.server.ServerContainer=org.eclipse.jetty.websocket.jsr356.server.ServerContainer@6fda53a8
      |   |   +> Context attributes o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}
      |   |   |   +- org.eclipse.jetty.util.DecoratedObjectFactory=org.eclipse.jetty.util.DecoratedObjectFactory[decorators=1]
      |   |   |   +- com.sun.jsp.tagFileJarUrlsCache={}
      |   |   |   +- org.springframework.web.context.support.ServletContextScope=org.springframework.web.context.support.ServletContextScope@30be2c30
      |   |   |   +- org.springframework.web.context.WebApplicationContext.ROOT=Root WebApplicationContext: startup date [Thu Mar 02 22:05:59 ICT 2017]; root of context hierarchy
      |   |   |   +- resourceCache=ResourceCache[null,org.eclipse.jetty.servlet.DefaultServlet@297785e5]@647951169
      |   |   |   +- org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration=org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration@468b9d9f
      |   |   |   +- org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter=WebSocketUpgradeFilter[configuration=org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration@468b9d9f]
      |   |   |   +- com.sun.jsp.taglibraryCache={}
      |   |   +> Initparams o.e.j.w.WebAppContext@3e778e26{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}
      |   |       +- contextConfigLocation=classpath:applicationContext.xml
      |   |       +- org.eclipse.jetty.servlet.Default.dirAllowed=false
      |   += o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data} - STARTED
      |       += org.eclipse.jetty.server.session.SessionHandler1013179752==dftMaxIdleSec=1800 - STARTED
      |       |   += org.eclipse.jetty.security.ConstraintSecurityHandler@7dfd9178 - STARTED
      |       |   |   +- org.eclipse.jetty.security.DefaultAuthenticatorFactory@68b06b8f
      |       |   |   += org.eclipse.jetty.servlet.ServletHandler@39e59923 - STARTED
      |       |   |   |   += org.eclipse.jetty.servlet.ListenerHolder@1a8e73d2 - STARTED
      |       |   |   |   += org.eclipse.jetty.servlet.ListenerHolder@b6957aa - STARTED
      |       |   |   |   += default@5c13d641==org.eclipse.jetty.servlet.DefaultServlet,jsp=null,order=0,inst=true - STARTED
      |       |   |   |   |   +- aliases=false
      |       |   |   |   |   +- dirAllowed=true
      |       |   |   |   |   +- maxCacheSize=256000000
      |       |   |   |   |   +- maxCachedFileSize=200000000
      |       |   |   |   |   +- welcomeServlets=false
      |       |   |   |   |   +- useFileMappedBuffer=true
      |       |   |   |   |   +- acceptRanges=true
      |       |   |   |   |   +- etags=false
      |       |   |   |   |   +- maxCachedFiles=2048
      |       |   |   |   |   +- redirectWelcome=false
      |       |   |   |   += jsp@19c47==org.eclipse.jetty.jsp.JettyJspServlet,jsp=null,order=0,inst=true - STARTED
      |       |   |   |   |   +- fork=false
      |       |   |   |   |   +- compilerSourceVM=1.7
      |       |   |   |   |   +- logVerbosityLevel=DEBUG
      |       |   |   |   |   +- compilerTargetVM=1.7
      |       |   |   |   |   +- scratchdir=/private/var/folders/8p/f__1hb6j0p5bq7ljqdkjg35h0000gn/T/jetty-0.0.0.0-8080-my_persistent-_myContext_persistent-any-707911495794918084.dir/jsp
      |       |   |   |   |   +- xpoweredBy=false
      |       |   |   |   +- [/]=>default
      |       |   |   |   +- [*.jsp, *.jspf, *.jspx, *.xsp, *.JSP, *.JSPF, *.JSPX, *.XSP]=>jsp
      |       |   |   |
      |       |   |   +> null
      |       |   |   +> null
      |       |   |   +> null
      |       |   |   +> []
      |       |   |   +> /={TRACE={RoleInfo,F,C[],None}, TRACE.omission={RoleInfo[],None}}
      |       |   += org.eclipse.jetty.server.session.DefaultSessionCache@606eb95b[evict=-1,removeUnloadable=false,saveOnCreate=false,saveOnInactiveEvict=false] - STARTED
      |       |   |   += org.eclipse.jetty.server.session.NullSessionDataStore@755718f4[passivating=false,graceSec=3600] - STARTED
      |       |   +~ org.eclipse.jetty.server.session.DefaultSessionIdManager@5bbef235[worker=node0] - STARTED
      |       += org.eclipse.jetty.servlet.ErrorPageErrorHandler@1c2ee56f - STARTED
      |       |
      |       +> WebAppClassLoader=1053927516@3ed1a85c
      |       |   +- sun.misc.Launcher$AppClassLoader@18b4aac2
      |       +> Systemclasses o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}
      |       |   +- java.
      |       |   +- javax.
      |       |   +- org.eclipse.jetty.continuation.
      |       |   +- org.eclipse.jetty.jaas.
      |       |   +- org.eclipse.jetty.jmx.
      |       |   +- org.eclipse.jetty.jndi.
      |       |   +- org.eclipse.jetty.jsp.JettyJspServlet
      |       |   +- org.eclipse.jetty.servlet.DefaultServlet
      |       |   +- org.eclipse.jetty.servlets.PushCacheFilter
      |       |   +- org.eclipse.jetty.servlets.PushSessionCacheFilter
      |       |   +- org.eclipse.jetty.util.annotation.
      |       |   +- org.eclipse.jetty.util.log.
      |       |   +- org.eclipse.jetty.websocket.
      |       |   +- org.w3c.
      |       |   +- org.xml.
      |       +> Serverclasses o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}
      |       |   +- -org.eclipse.jetty.alpn.
      |       |   +- -org.eclipse.jetty.apache.
      |       |   +- -org.eclipse.jetty.continuation.
      |       |   +- -org.eclipse.jetty.jaas.
      |       |   +- -org.eclipse.jetty.jmx.
      |       |   +- -org.eclipse.jetty.jndi.
      |       |   +- -org.eclipse.jetty.jsp.
      |       |   +- -org.eclipse.jetty.server.session.SessionData
      |       |   +- -org.eclipse.jetty.servlet.DefaultServlet
      |       |   +- -org.eclipse.jetty.servlet.NoJspServlet
      |       |   +- -org.eclipse.jetty.servlet.listener.
      |       |   +- -org.eclipse.jetty.servlets.
      |       |   +- -org.eclipse.jetty.util.annotation.
      |       |   +- -org.eclipse.jetty.util.log.
      |       |   +- -org.eclipse.jetty.websocket.
      |       |   +- org.eclipse.jdt.
      |       |   +- org.eclipse.jetty.
      |       |   +- org.objectweb.asm.
      |       +> Configurations o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}
      |       |   +- org.eclipse.jetty.webapp.WebInfConfiguration@5d3b3547
      |       |   +- org.eclipse.jetty.webapp.WebXmlConfiguration@488aebda
      |       |   +- org.eclipse.jetty.webapp.MetaInfConfiguration@5d7da87
      |       |   +- org.eclipse.jetty.webapp.FragmentConfiguration@6eb942cf
      |       |   +- org.eclipse.jetty.webapp.JettyWebXmlConfiguration@6a2cd352
      |       +> Handler attributes o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}
      |       |   +- javax.servlet.context.tempdir=/private/var/folders/8p/f__1hb6j0p5bq7ljqdkjg35h0000gn/T/jetty-0.0.0.0-8080-my_persistent-_myContext_persistent-any-707911495794918084.dir
      |       |   +- org.eclipse.jetty.server.Executor=qtp348159759{STARTED,10<=20<=200,i=2,q=0}
      |       +> Context attributes o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}
      |       |   +- org.eclipse.jetty.util.DecoratedObjectFactory=org.eclipse.jetty.util.DecoratedObjectFactory[decorators=1]
      |       |   +- com.sun.jsp.tagFileJarUrlsCache={}
      |       |   +- resourceCache=ResourceCache[null,org.eclipse.jetty.servlet.DefaultServlet@756731f6]@1323290175
      |       |   +- com.sun.jsp.taglibraryCache={}
      |       +> Initparams o.e.j.w.WebAppContext@2974d7ef{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}
      |           +- org.eclipse.jetty.servlet.Default.dirAllowed=false
      += org.eclipse.jetty.server.handler.ErrorHandler@6ad45211 - STARTED
      +- {}
      +- {}
      +- {}
      += org.eclipse.jetty.server.session.DefaultSessionIdManager@5bbef235[worker=node0] - STARTED
      |   += org.eclipse.jetty.server.session.HouseKeeper@666eba5a[interval=600000, ownscheduler=false] - STARTED
      |
      +> sun.misc.Launcher$AppClassLoader@18b4aac2
          [LIBS]
          +- sun.misc.Launcher$ExtClassLoader@fae8daf
    

The above code works fine with Jetty 9.1.5.v20140505 and Java 7 but when fail when I upgrade to Jetty 9.4.1.v20170120 and Java 8. Browser console report an 404 error.

WebSocket connection to 'wss://localhost:8443/myContext/ws/communication/5/kbui/None' failed: Unexpected response code: 404

Did I miss something when upgrade Jetty?
Thanks in advance.


Solution

  • Judging from your setup, you'll wind up with ...

    wss://localhost:8443/myContext/ws/communication/5/kbui/None

    Your contextPath isn't /context, its actually /myContext in your setup.

    You trimmed out the Servlet Mappings section on the dump (that was the important part. heh)

    But attempting to manually add the WSCommunication Endpoint contained in WebAppContext from outside of the WebAppClassloader or the WebApp's ServletContext is probably going to be a problem as well.

    You have 3 options:

    1. The JSR356 Automatic Way

      Setup bytecode scanning and annotation discovery for your WebAppContext and let the startup discover and auto-load the WSCommunication endpoint.

      Add the following to your webContext ...

    webContext.setAttribute("org.eclipse.jetty.websocket.jsr356",Boolean.TRUE);
    
    webContext.setConfigurations(new Configuration[] {
                new AnnotationConfiguration(),
                new WebXmlConfiguration(),
                new WebInfConfiguration(),
                new PlusConfiguration(), 
                new MetaInfConfiguration(),
                new FragmentConfiguration(), 
                new EnvConfiguration()});
    

    And add the jetty-annotations dependency to your project.

    1. The JSR356 Manual Way

      Use the javax.websocket.server.ServerApplicationConfig to report the WSCommunication as being available to be added from within the webapp's startup.

    2. The Servlet Spec Manual Way

      This is the easiest approach. Create a javax.servlet.ServletContextListener that adds the WSCommunication endpoint to the ServerContainer

    public class MyContextListener implements ServletContextListener
    {
        @Override
        public void contextDestroyed(ServletContextEvent sce)
        {
        }
    
        @Override
        public void contextInitialized(ServletContextEvent sce)
        {
            ServerContainer container = (ServerContainer)sce.getServletContext()
                       .getAttribute(ServerContainer.class.getName());
    
            try
            {
                container.addEndpoint(WSCommunication.class);
            }
            catch (DeploymentException e)
            {
                throw new RuntimeException("Unable to add endpoint",e);
            }
        }
    }