Websocket JSR-356在Jetty 9.4.1中失败 [英] Websocket JSR-356 fail with Jetty 9.4.1

查看:116
本文介绍了Websocket JSR-356在Jetty 9.4.1中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的Web服务器是嵌入式Jetty 9.1.5。它与JSR-356一起很好地创建websocket。这些天,我正在尝试升级到Jetty 9.4.1。除了websocket之外,其他所有东西都运行良好。

我的代码如下:

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. 嵌入式码头和Websocket库:




<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. 服务器端点:




  @ServerEndpoint(value = "/ws/communication/{officeId}/{username}/{oldWSSession}")
  class WSCommunication {
     // @OnOpen, @OnMessage, @OnClose methods
  }





  1. Jetty服务器,Webapp上下文, Websocket配置:

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



  • 转储:

  • 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
    



  • 上面的代码在Jetty 9.1.5.v20140505和Java 7上运行良好,但是当我失败时升级到Jetty 9.4.1.v20170120和Java8。
    浏览器控制台报告404错误。

    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
    

    升级Jetty时是否错过了某些东西?

    预先感谢。

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

    推荐答案

    从您的设置来看,您将得到...

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

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

    您的 contextPath 不是 / context ,实际上是您设置中的 / myContext

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

    转储上的Servlet映射部分(t帽子是重要的部分。 heh)

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

    但是尝试手动添加 WebAppContext WSCommunication 端点从 WebAppClassloader 或WebApp的ServletContext外部访问c $ c>也可能是一个问题。

    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.

    您有3种选择:


    1. JSR356自动方式

    为您的 WebAppContext 设置字节码扫描和注释发现,并让启动程序发现并自动加载 WSCommunication 端点。

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

    将以下内容添加到您的 webContext ...

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

    并将 jetty-annotations 依赖项添加到您的项目。

    And add the jetty-annotations dependency to your project.


    1. JSR356手动方式

    使用 javax.websocket.server.ServerApplicationConfig 报告 WSCommunication

    Servlet规范手册方法

    这是最简单的方法。
    创建一个 javax.servlet.ServletContextListener ,将 WSCommunication 端点添加到 ServerContainer

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

    这篇关于Websocket JSR-356在Jetty 9.4.1中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆