update 优化 webscoket 配置与异常拦截
| | |
| | | @AutoConfiguration |
| | | public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServletWebServerFactory> { |
| | | |
| | | /** |
| | | * 设置 Undertow 的 websocket 缓冲池 |
| | | */ |
| | | @Override |
| | | public void customize(UndertowServletWebServerFactory factory) { |
| | | // 默认不直接分配内存 如果项目中使用了 websocket 建议直接分配 |
| | | factory.addDeploymentInfoCustomizers(deploymentInfo -> { |
| | | WebSocketDeploymentInfo webSocketDeploymentInfo = new WebSocketDeploymentInfo(); |
| | | webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(false, 512)); |
| | | webSocketDeploymentInfo.setBuffers(new DefaultByteBufferPool(true, 1024)); |
| | | deploymentInfo.addServletContextAttribute("io.undertow.websockets.jsr.WebSocketDeploymentInfo", webSocketDeploymentInfo); |
| | | // 使用虚拟线程 |
| | | if (SpringUtils.isVirtual()) { |
| | |
| | | */ |
| | | @Override |
| | | public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) { |
| | | try { |
| | | // 检查是否登录 是否有token |
| | | LoginUser loginUser = LoginHelper.getLoginUser(); |
| | | |
| | |
| | | |
| | | attributes.put(LOGIN_USER_KEY, loginUser); |
| | | return true; |
| | | } catch (NotLoginException e) { |
| | | log.error("WebSocket 认证失败'{}',无法访问系统资源", e.getMessage()); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | /** |