Commit ca65267f6d224de3ca381615705a4dfd1839cdee
1 parent
5cbba763
fix:CacheRequestBodyFilter 导致 Spring Boot Admin 无法修改日志级别,https://github.com/Yuna…
…iV/ruoyi-vue-pro/issues/795
Showing
1 changed file
with
16 additions
and
1 deletions
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/web/core/filter/CacheRequestBodyFilter.java
| 1 | 1 | package cn.iocoder.yudao.framework.web.core.filter; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.StrUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 4 | 5 | import org.springframework.web.filter.OncePerRequestFilter; |
| 5 | 6 | |
| ... | ... | @@ -16,6 +17,14 @@ import java.io.IOException; |
| 16 | 17 | */ |
| 17 | 18 | public class CacheRequestBodyFilter extends OncePerRequestFilter { |
| 18 | 19 | |
| 20 | + /** | |
| 21 | + * 需要排除的 URI | |
| 22 | + * | |
| 23 | + * 1. 排除 Spring Boot Admin 相关请求,避免客户端连接中断导致的异常。 | |
| 24 | + * 例如说:<a href="https://github.com/YunaiV/ruoyi-vue-pro/issues/795">795 ISSUE</a> | |
| 25 | + */ | |
| 26 | + private static final String[] IGNORE_URIS = {"/admin", "/actuator"}; | |
| 27 | + | |
| 19 | 28 | @Override |
| 20 | 29 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
| 21 | 30 | throws IOException, ServletException { |
| ... | ... | @@ -24,7 +33,13 @@ public class CacheRequestBodyFilter extends OncePerRequestFilter { |
| 24 | 33 | |
| 25 | 34 | @Override |
| 26 | 35 | protected boolean shouldNotFilter(HttpServletRequest request) { |
| 27 | - // 只处理 json 请求内容 | |
| 36 | + // 1. 校验是否为排除的 URL | |
| 37 | + String requestURI = request.getRequestURI(); | |
| 38 | + if (StrUtil.containsAny(requestURI, IGNORE_URIS)) { | |
| 39 | + return true; | |
| 40 | + } | |
| 41 | + | |
| 42 | + // 2. 只处理 json 请求内容 | |
| 28 | 43 | return !ServletUtils.isJsonRequest(request); |
| 29 | 44 | } |
| 30 | 45 | ... | ... |