2017-03-01 69 views
0

我目前的Web服务器是嵌入Jetty 9.1.5。它适用于JSR-356来创建websocket。这些天,我正在尝试升级到Jetty 9.4.1。除了websocket,一切都很好。
我的代码象下面这样:Websocket JSR-356与Jetty失败9.4.1

  1. 嵌入式码头和网页套接字库:
<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> 
  • 服务器端点:
  • @ServerEndpoint(value = "/ws/communication/{officeId}/{username}/{oldWSSession}") 
        class WSCommunication { 
        // @OnOpen, @OnMessage, @OnClose methods 
        } 
    
  • 码头服务器,的webapp上下文,WebSocket的配置:

    // 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(); 
    
  • 转储:

    [email protected] - 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 [email protected]@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 [email protected]@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 
         += [email protected]d - 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) 
         += [email protected]{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} - STARTED 
         | +~ [email protected] - STARTED 
         | +~ qtp348159759{STARTED,10<=19<=200,i=1,q=0} - STARTED 
         | +~ [email protected]d - STARTED 
         | +- [email protected] 
         | += [email protected][HTTP/1.1] - STARTED 
         | | +- [email protected]{32768/8192,8192/8192,https://:8443,[]} 
         | += [email protected]282048ea - STARTED 
         | | += [email protected] id=0 keys=0 selected=0 id=0 
         | | | +- [email protected] keys=0 
         | | += [email protected] id=1 keys=0 selected=0 id=1 
         | | | +- [email protected] keys=0 
         | | += [email protected] id=2 keys=0 selected=0 id=2 
         | | | +- [email protected] keys=0 
         | | += [email protected] id=3 keys=0 selected=0 id=3 
         | |  +- [email protected] keys=0 
         | +- sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:8080] 
         | +- [email protected]@52bab8e{HTTP/1.1,[http/1.1]}{0.0.0.0:8080} 
         += [email protected]{SSL,[ssl, http/1.1]}{0.0.0.0:8443} - STARTED 
         | +~ [email protected] - STARTED 
         | +~ qtp348159759{STARTED,10<=20<=200,i=2,q=0} - STARTED 
         | +~ [email protected]d - STARTED 
         | +- [email protected] 
         | += [email protected]{SSL->http/1.1} - STARTED 
         | | += [email protected](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] 
         | += [email protected][HTTP/1.1] - STARTED 
         | | +- [email protected]{32768/8192,8192/8192,https://:8443,[[email protected]]} 
         | += [email protected]14690caf - STARTED 
         | | += [email protected] id=0 keys=0 selected=0 id=0 
         | | | +- [email protected] keys=0 
         | | += [email protected] id=1 keys=0 selected=0 id=1 
         | | | +- [email protected] keys=0 
         | | += [email protected] id=2 keys=0 selected=0 id=2 
         | | | +- [email protected] keys=0 
         | | += [email protected] id=3 keys=0 selected=0 id=3 
         | |  +- [email protected] keys=0 
         | +- sun.nio.ch.ServerSocketChannelImpl[/0:0:0:0:0:0:0:0:8443] 
         | +- [email protected]@31de14e{SSL,[ssl, http/1.1]}{0.0.0.0:8443} 
         += [email protected]7e[[email protected]{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps}, [email protected]{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data}] - STARTED 
         | += [email protected]{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps} - STARTED 
         | | += org.eclipse.jetty.server.session.SessionHandler589427621==dftMaxIdleSec=1800 - STARTED 
         | | | += [email protected] - STARTED 
         | | | | +- [email protected] 
         | | | | += [email protected] - STARTED 
         | | | | | += [email protected] - STARTED 
         | | | | | += [email protected] - STARTED 
         | | | | | += [email protected]==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 
         | | | | | += [email protected]==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 
         | | | | | += [email protected] - STARTED 
         | | | | | += [email protected] - STARTED 
         | | | | | += ISSSecurityFilter - STARTED 
         | | | | | += GzipFilter - STARTED 
         | | | | | | +- mimeTypes=text/plain,text/html,text/css,application/javascript,application/x-javascript,application/json 
         | | | | | += [email protected]==com.example.web.Dashboard,jsp=null,order=1,inst=true - STARTED 
         | | | | | | +- parameter=value 
         | | | | | += [email protected]==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}} 
        | | | +~ [email protected] 
        | | | += [email protected][evict=-1,removeUnloadable=false,saveOnCreate=false,saveOnInactiveEvict=false] - STARTED 
        | | | | += [email protected][passivating=false,graceSec=3600] - STARTED 
        | | | +~ [email protected]5[worker=node0] - STARTED 
        | | += [email protected] - STARTED 
        | | +~ [email protected]a8 - STOPPED 
        | | | 
        | | +> [email protected] 
        | | | [LIBS] 
        | | | +- [email protected] 
        | | +> Systemclasses [email protected]{/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 [email protected]{/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 [email protected]{/myContext,file:///workspace/myApp/myApp-server/webapps/myContext/,AVAILABLE}{/workspace/myApp/myApp-server/webapps} 
        | | | +- [email protected] 
        | | | +- [email protected] 
        | | | +- [email protected] 
        | | | +- [email protected] 
        | | | +- [email protected] 
        | | +> Handler attributes [email protected]{/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=[email protected]468b9d9f] 
        | | | +- org.eclipse.jetty.server.Executor=qtp348159759{STARTED,10<=20<=200,i=2,q=0} 
        | | | +- org.apache.catalina.jsp_classpath=[LIBS] 
        | | | +- javax.websocket.server.ServerCont[email protected]6fda53a8 
        | | +> Context attributes [email protected]{/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.ServletContextSc[email protected]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,[email protected]]@647951169 
        | | | +- org.eclipse.jetty.websocket.server.NativeWebSocketConfiguration=[email protected]468b9d9f 
        | | | +- org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter=WebSocketUpgradeFilter[configuration=[email protected]468b9d9f] 
        | | | +- com.sun.jsp.taglibraryCache={} 
        | | +> Initparams [email protected]{/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 
        | += [email protected]{/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 
        |  | += [email protected] - STARTED 
        |  | | +- [email protected] 
        |  | | += [email protected] - STARTED 
        |  | | | += [email protected] - STARTED 
        |  | | | += [email protected] - STARTED 
        |  | | | += [email protected]==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 
        |  | | | += [email protected]==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}} 
        |  | += [email protected][evict=-1,removeUnloadable=false,saveOnCreate=false,saveOnInactiveEvict=false] - STARTED 
        |  | | += [email protected][passivating=false,graceSec=3600] - STARTED 
        |  | +~ [email protected]5[worker=node0] - STARTED 
        |  += [email protected] - STARTED 
        |  | 
        |  +> [email protected] 
        |  | +- [email protected] 
        |  +> Systemclasses [email protected]{/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 [email protected]{/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 [email protected]{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data} 
        |  | +- [email protected] 
        |  | +- [email protected] 
        |  | +- [email protected] 
        |  | +- [email protected] 
        |  | +- [email protected] 
        |  +> Handler attributes [email protected]{/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 [email protected]{/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,[email protected]]@1323290175 
        |  | +- com.sun.jsp.taglibraryCache={} 
        |  +> Initparams [email protected]{/myContext_persistent,file:///workspace/myApp/myApp-server/data/my_persistent/,AVAILABLE}{/workspace/myApp/myApp-server/data} 
        |   +- org.eclipse.jetty.servlet.Default.dirAllowed=false 
        += [email protected] - STARTED 
        +- {} 
        +- {} 
        +- {} 
        += [email protected]5[worker=node0] - STARTED 
        | += [email protected][interval=600000, ownscheduler=false] - STARTED 
        | 
        +> [email protected] 
         [LIBS] 
         +- [email protected] 
    
  • 上面的代码在Jetty 9.1.5.v20140505和Java 7中正常工作,但当升级到Jetty 9.4.1.v20170120和Java 8时失败。 浏览器控制台报告404错误。

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

    我在升级Jetty时错过了什么吗?
    在此先感谢。

    +0

    什么是你webContext初始化样子? –

    +1

    转储您的服务器(启动后)并在您的问题中报告其树。 'server.dumpStdErr();' –

    +0

    我修改后添加服务器,Webapp上下文代码。 –

    回答

    0

    从你的设置来看,你会得...

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

    contextPath/context,它实际上/myContext在您的设置。

    你修剪出在垃圾堆里的servlet映射部分(这是重要的组成部分。嘿嘿)

    但尝试手动添加从WebAppClassloader或Web应用程序的ServletContext中的外WebAppContext包含WSCommunication端点很可能将也是一个问题。

    你有3种选择:

    1. 的JSR356自动方式

      设置字节码扫描和注释发现你WebAppContext,让启动发现和自动加载WSCommunication端点。

      将以下内容添加到您的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依赖于你的项目。

  • 的JSR356手动方式

    使用javax.websocket.server.ServerApplicationConfig来报告WSCommunication为可用以从web应用程序的启动中加入。

  • Servlet规范手工方式

    这是最简单的方法。 创建javax.servlet.ServletContextListener,增加了WSCommunication端点到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); 
         } 
        } 
    } 
    
    +0

    我尝试#1的方法,它的作用就像一个魅力。非常感谢。 –

    +0

    关于以前的代码如何在9.1.5上工作,你的意思是我设置websocket错误,但9.1.5仍然接受,到9.4.1 Jetty服务器更严格,然后拒绝。对? –

    +0

    另一个问题,在现实中,我的服务器可能支持多个上下文,所有3种方法仍然可以与多个WebAppContext一起使用? –