From 686068c8ed0137cc937a4894f3e110c58ed5b8c8 Mon Sep 17 00:00:00 2001 From: zendwang Date: Mon, 4 Jul 2022 11:30:43 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=E9=AD=94=E6=B3=95?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/filter/RepeatedlyRequestWrapper.java | 5 +++-- .../src/main/java/com/ruoyi/common/filter/XssFilter.java | 3 ++- .../ruoyi/common/filter/XssHttpServletRequestWrapper.java | 3 +-- .../src/main/java/com/ruoyi/common/utils/ServletUtils.java | 2 +- .../main/java/com/xxl/job/admin/core/util/JacksonUtil.java | 4 ++-- .../framework/interceptor/PlusWebInvokeTimeInterceptor.java | 6 ++++-- 6 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java b/ruoyi-common/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java index b6fd0b65..ca76e76c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java @@ -1,6 +1,7 @@ package com.ruoyi.common.filter; import cn.hutool.core.io.IoUtil; +import com.ruoyi.common.constant.Constants; import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; @@ -23,8 +24,8 @@ public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper { public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException { super(request); - request.setCharacterEncoding("UTF-8"); - response.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(Constants.UTF8); + response.setCharacterEncoding(Constants.UTF8); body = IoUtil.readUtf8(request.getInputStream()).getBytes(StandardCharsets.UTF_8); } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java index 72a8f274..7494e87b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java @@ -1,5 +1,6 @@ package com.ruoyi.common.filter; +import cn.hutool.extra.servlet.ServletUtil; import com.ruoyi.common.utils.StringUtils; import javax.servlet.*; @@ -48,7 +49,7 @@ public class XssFilter implements Filter { String url = request.getServletPath(); String method = request.getMethod(); // GET DELETE 不过滤 - if (method == null || method.matches("GET") || method.matches("DELETE")) { + if (method == null || method.matches(ServletUtil.METHOD_GET) || method.matches(ServletUtil.METHOD_DELETE)) { return true; } return StringUtils.matches(url, excludes); diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java index a8ffd66c..f1b51315 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java @@ -89,10 +89,9 @@ public class XssHttpServletRequestWrapper extends HttpServletRequestWrapper { /** * 是否是Json请求 * - * @param request */ public boolean isJsonRequest() { String header = super.getHeader(HttpHeaders.CONTENT_TYPE); return StringUtils.startsWithIgnoreCase(header, MediaType.APPLICATION_JSON_VALUE); } -} \ No newline at end of file +} diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java index 6408c894..84079c4b 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ServletUtils.java @@ -117,7 +117,7 @@ public class ServletUtils extends ServletUtil { public static boolean isAjaxRequest(HttpServletRequest request) { String accept = request.getHeader("accept"); - if (accept != null && accept.contains("application/json")) { + if (accept != null && accept.contains(MediaType.APPLICATION_JSON_VALUE)) { return true; } diff --git a/ruoyi-extend/ruoyi-xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JacksonUtil.java b/ruoyi-extend/ruoyi-xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JacksonUtil.java index a7559568..0312b747 100644 --- a/ruoyi-extend/ruoyi-xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JacksonUtil.java +++ b/ruoyi-extend/ruoyi-xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/JacksonUtil.java @@ -21,10 +21,10 @@ import java.io.IOException; public class JacksonUtil { private static Logger logger = LoggerFactory.getLogger(JacksonUtil.class); - private final static ObjectMapper objectMapper = new ObjectMapper(); + private final static ObjectMapper OBJECT_MAPPER = new ObjectMapper(); public static ObjectMapper getInstance() { - return objectMapper; + return OBJECT_MAPPER; } /** diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/PlusWebInvokeTimeInterceptor.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/PlusWebInvokeTimeInterceptor.java index 9ba4cff8..734ca1aa 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/PlusWebInvokeTimeInterceptor.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/interceptor/PlusWebInvokeTimeInterceptor.java @@ -28,11 +28,13 @@ import java.util.Map; @Slf4j public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor { + public static final String PROD_PROFILE = "prod"; + private final TransmittableThreadLocal invokeTimeTL = new TransmittableThreadLocal<>(); @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - if (!"prod".equals(SpringUtils.getActiveProfile())) { + if (!PROD_PROFILE.equals(SpringUtils.getActiveProfile())) { String url = request.getMethod() + " " + request.getRequestURI(); // 打印请求参数 @@ -67,7 +69,7 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor { @Override public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception { - if (!"prod".equals(SpringUtils.getActiveProfile())) { + if (!PROD_PROFILE.equals(SpringUtils.getActiveProfile())) { StopWatch stopWatch = invokeTimeTL.get(); stopWatch.stop(); log.debug("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());