错误是:
org.springframework.web.socket.server.HandshakeFailureException:错误 在握手期间:http://2.12.85.0:6/eto/tvoy;嵌套异常是 java.lang.IllegalStateException:对此禁用了async-support request:weblogic.servlet.internal.ServletRequestImpl
服务器:WebLogic 12。 当我尝试连接websocket时会出现。
我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!--Позволяет работать с русскими символами-->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter>
<filter-name>AFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>AFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我的webSocketConfig:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
@Configuration
@EnableWebSocket
@EnableAsync
public class WebSocketConfig implements WebSocketConfigurer {
private static final Logger log = LoggerFactory.getLogger("webSocketLogger");
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
log.error("registerWebSocketHandlers");
registry.addHandler(webSocketHandler(), "/chat").setAllowedOrigins("*");
}
@Bean
public WebSocketHandler webSocketHandler() {
return new workspace.websocket.controller.WebSocketHandler();
}
}
我的websocket处理程序:
public class WebSocketHandler implements org.springframework.web.socket.WebSocketHandler {
private static final Logger log = LoggerFactory.getLogger("webSocketLogger");
@Override
public void afterConnectionEstablished(WebSocketSession webSocketSession) throws Exception {
}
@Override
public void handleMessage(WebSocketSession webSocketSession, WebSocketMessage<?> webSocketMessage) throws Exception {
}
@Override
public void handleTransportError(WebSocketSession webSocketSession, Throwable throwable) throws Exception {
log.error("transport error", throwable);
}
@Override
public void afterConnectionClosed(WebSocketSession webSocketSession, CloseStatus closeStatus) throws Exception {
}
@Override
public boolean supportsPartialMessages() {
return false;
}
}
我该怎么办?
答案 0 :(得分:0)
对于使用异步功能的应用程序,整个请求处理链必须通过注释或其部署描述符设置此属性。如果应用程序尝试启动异步操作并且请求处理链中存在不支持异步处理的servlet或servlet过滤器,则将抛出IllegalStateException。因此,要解决这个问题,必须为这组过滤器添加一个额外的元素:
<async-supported>true</async-supported>
在您的web.xml中,您缺少此编码过滤器。所以你的编码过滤器配置应该是这样的:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>