From 3843898ec8317c114c85a6633bd241f23dca643c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Fri, 2 Aug 2024 09:37:08 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20sse=20=E6=8B=A6?= =?UTF-8?q?=E6=88=AA=E7=BD=91=E7=BB=9C=E4=B8=AD=E6=96=ADio=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/sse/core/SseEmitterManager.java | 6 ------ .../web/handler/GlobalExceptionHandler.java | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java b/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java index aa7960c2..039e17f4 100644 --- a/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java +++ b/ruoyi-common/ruoyi-common-sse/src/main/java/org/dromara/common/sse/core/SseEmitterManager.java @@ -1,6 +1,5 @@ package org.dromara.common.sse.core; -import cn.dev33.satoken.stp.StpUtil; import cn.hutool.core.collection.CollUtil; import lombok.extern.slf4j.Slf4j; import org.dromara.common.redis.utils.RedisUtils; @@ -72,11 +71,6 @@ public class SseEmitterManager { if (emitters != null) { for (Map.Entry entry : emitters.entrySet()) { try { - // token 无效或已过期 - if (StpUtil.stpLogic.getTokenActiveTimeoutByToken(entry.getKey()) < -1) { - emitters.remove(entry.getKey()); - continue; - } entry.getValue().send(SseEmitter.event() .name("message") .data(message)); diff --git a/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java index bd47c189..061d3aa4 100644 --- a/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java +++ b/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/handler/GlobalExceptionHandler.java @@ -16,10 +16,13 @@ import org.springframework.web.HttpRequestMethodNotSupportedException; import org.springframework.web.bind.MethodArgumentNotValidException; import org.springframework.web.bind.MissingPathVariableException; import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestControllerAdvice; import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.servlet.NoHandlerFoundException; +import java.io.IOException; + /** * 全局异常处理器 * @@ -89,6 +92,20 @@ public class GlobalExceptionHandler { return R.fail(HttpStatus.HTTP_NOT_FOUND, e.getMessage()); } + /** + * 拦截未知的运行时异常 + */ + @ResponseStatus(org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR) + @ExceptionHandler(IOException.class) + public void handleRuntimeException(IOException e, HttpServletRequest request) { + String requestURI = request.getRequestURI(); + if (requestURI.contains("sse")) { + // sse 经常性连接中断 例如关闭浏览器 直接屏蔽 + return; + } + log.error("请求地址'{}',连接中断", requestURI, e); + } + /** * 拦截未知的运行时异常 */