使用spring4+tomcat8,运行后,报错,提示 The extensi?报错-问答-阿里云开发者社区-阿里云

开发者社区> 问答> 正文

使用spring4+tomcat8,运行后,报错,提示 The extensi?报错

爱吃鱼的程序员 2020-06-12 14:28:57 30

刚接触这个,使用spring4+tomcat8,运行后,报错,提示  

2015-08-18 21:40:30,194[org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver]-[DEBUG] Resolving exception from handler [org.springframework.web.socket.server.support.WebSocketHttpRequestHandler@59a6cc]: org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:8080/spring4/myHandler; nested exception is java.lang.IllegalArgumentException: The extension [x-webkit-deflate-frame] is not supported

2015-08-18 21:40:30,195 [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver]-[DEBUG] Resolving exception from handler [org.springframework.web.socket.server.support.WebSocketHttpRequestHandler@59a6cc]: org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:8080/spring4/myHandler; nested exception is java.lang.IllegalArgumentException: The extension [x-webkit-deflate-frame] is not supported
2015-08-18 21:40:30,196 [org.springframework.web.servlet.DispatcherServlet]-[DEBUG] Could not complete request
org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://localhost:8080/spring4/myHandler; nested exception is java.lang.IllegalArgumentException: The extension [x-webkit-deflate-frame] is not supported
at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:128)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
分享到
取消 提交回答
全部回答(1)
  • 爱吃鱼的程序员
    2020-06-12 14:29:16

    这个说明浏览器比较旧(估计是safari,至少safari6就是这样,safari8不知道有无此问题),对于websocket压缩还是用的很老的非规范的扩展“x-webkit-deflate-frame”,新的firefox,chrome都不会发这个扩展头信息,而是发送草案中规范的“permessage-deflate”。但是另外spring4对于这个非规范的老扩展兼容也不太好(其实就是bug),按理应该忽略这个扩展,让tomcat和浏览器进行非压缩的websocket通讯即可。<spanstyle="font-size:13.3333330154419px;">spring4看起来比较矫情,它采取了抛异常,这是不合理的。而tomcat8自带的examples中websocket的例子对于“<spanstyle="font-size:13.3333330154419px;">x-webkit-deflate-frame”不会出问题,因为tomcat8对于<spanstyle="font-size:13.3333330154419px;">x-webkit-deflate-frame是采取忽略的态度,不回发压缩扩展协商成功的头,即表明采用非压缩方式传输,这样就没有问题了。

    web.socket

    看起来你的浏览器不支持,导致spring的这个扩展也报错了

    我试过多个浏览器都还是一样

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">org.springframework.web.socket.server.HandshakeFailureException:Uncaughtfailureforrequesthttp://localhost:8080/spring4/myHandler;nestedexceptionisjava.lang.IllegalArgumentException:Theextension[x-webkit-deflate-frame]isnotsupported

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> 注意这个估计是websocket的问题 <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">spring4/myHandler这个是你自己写的吧问题在这

    <divclass='ref'>

    引用来自“苏大泉”的评论

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">org.springframework.web.socket.server.HandshakeFailureException:Uncaughtfailureforrequesthttp://localhost:8080/spring4/myHandler;nestedexceptionisjava.lang.IllegalArgumentException:Theextension[x-webkit-deflate-frame]isnotsupported

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">

    <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"> 注意这个估计是websocket的问题 <spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">spring4/myHandler这个是你自己写的吧问题在这

    <divclass='ref'>

    引用来自“xfeep”的评论

    这个说明浏览器比较旧(估计是safari,至少safari6就是这样,safari8不知道有无此问题),对于websocket压缩还是用的很老的非规范的扩展“x-webkit-deflate-frame”,新的firefox,chrome都不会发这个扩展头信息,而是发送草案中规范的“permessage-deflate” 。但是另外spring4对于这个非规范的老扩展兼容也不太好(其实就是bug),按理应该忽略这个扩展,让tomcat和浏览器进行非压缩的websocket通讯即可。<spanstyle="font-size:13.3333330154419px;">spring4看起来比较矫情,它采取了抛异常,这是不合理的。而tomcat8自带的examples中websocket的例子对于“<spanstyle="font-size:13.3333330154419px;">x-webkit-deflate-frame”不会出问题,因为tomcat8对于<spanstyle="font-size:13.3333330154419px;">x-webkit-deflate-frame是采取忽略的态度,不回发压缩扩展协商成功的头,即表明采用非压缩方式传输,这样就没有问题了。关键是应该怎么解决这个问题呢?spring4+tomcat8,safari8也是同样的问题。
    直接用tomcat8(比如8.0.24)的websocekt肯定可以和safari通讯的,而且也不复杂;如果一定要用spring,那么在upgradeStrategy上面做些事情应该是可以的,比如用TomcatRequestUpgradeStrategy试试。因为本人不用这些,所以没有时间去尝试,但原理是确是可行的。可以使用自定义Interceptor解决这个问题。比如这样:
     registry.addHandler(systemWebSocketHandler(),"/webSocketServer").addInterceptors(newHandshakeInterceptor(){
             
             @Override
             publicbooleanbeforeHandshake(ServerHttpRequestarg0,ServerHttpResponsearg1,WebSocketHandlerarg2,Map<String,Object>arg3)throwsException{
                //
                if(arg0.getHeaders().containsKey("Sec-WebSocket-Extensions")){
                   arg0.getHeaders().set("Sec-WebSocket-Extensions","permessage-deflate");
                }
                returntrue;
             }
             
             @Override
             publicvoidafterHandshake(ServerHttpRequestarg0,ServerHttpResponsearg1,WebSocketHandlerarg2,Exceptionarg3){
                //TODOAuto-generatedmethodstub
                
             }
          });
    <divclass='ref'>

    引用来自“钱学超”的评论

    可以使用自定义Interceptor解决这个问题。比如这样:
     registry.addHandler(systemWebSocketHandler(),"/webSocketServer").addInterceptors(newHandshakeInterceptor(){
             
             @Override
             publicbooleanbeforeHandshake(ServerHttpRequestarg0,ServerHttpResponsearg1,WebSocketHandlerarg2,Map<String,Object>arg3)throwsException{
                //
                if(arg0.getHeaders().containsKey("Sec-WebSocket-Extensions")){
                   arg0.getHeaders().set("Sec-WebSocket-Extensions","permessage-deflate");
                }
                returntrue;
             }
             
             @Override
             publicvoidafterHandshake(ServerHttpRequestarg0,ServerHttpResponsearg1,WebSocketHandlerarg2,Exceptionarg3){
                //TODOAuto-generatedmethodstub
                
             }
          });

    0 0
云计算
使用钉钉扫一扫加入圈子
+ 订阅

时时分享云计算技术内容,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。

推荐文章