update 优化 sse 拦截网络中断io异常
This commit is contained in:
parent
b886f3a04b
commit
615ad918ca
@ -1,6 +1,5 @@
|
|||||||
package org.dromara.common.sse.core;
|
package org.dromara.common.sse.core;
|
||||||
|
|
||||||
import cn.dev33.satoken.stp.StpUtil;
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.common.redis.utils.RedisUtils;
|
import org.dromara.common.redis.utils.RedisUtils;
|
||||||
@ -72,11 +71,6 @@ public class SseEmitterManager {
|
|||||||
if (emitters != null) {
|
if (emitters != null) {
|
||||||
for (Map.Entry<String, SseEmitter> entry : emitters.entrySet()) {
|
for (Map.Entry<String, SseEmitter> entry : emitters.entrySet()) {
|
||||||
try {
|
try {
|
||||||
// token 无效或已过期
|
|
||||||
if (StpUtil.stpLogic.getTokenActiveTimeoutByToken(entry.getKey()) < -1) {
|
|
||||||
emitters.remove(entry.getKey());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
entry.getValue().send(SseEmitter.event()
|
entry.getValue().send(SseEmitter.event()
|
||||||
.name("message")
|
.name("message")
|
||||||
.data(message));
|
.data(message));
|
||||||
|
@ -16,10 +16,13 @@ import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|||||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||||
import org.springframework.web.bind.MissingPathVariableException;
|
import org.springframework.web.bind.MissingPathVariableException;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
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.bind.annotation.RestControllerAdvice;
|
||||||
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
|
||||||
import org.springframework.web.servlet.NoHandlerFoundException;
|
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());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 拦截未知的运行时异常
|
* 拦截未知的运行时异常
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user