【fix sonar】AutoLogAspect文件

This commit is contained in:
梁琦涛
2023-03-09 12:01:34 +08:00
parent aae0295ffd
commit e79718d7f1
@@ -29,7 +29,9 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
@@ -152,8 +154,9 @@ public class AutoLogAspect {
*/ */
private String getReqestParams(HttpServletRequest request, JoinPoint joinPoint) { private String getReqestParams(HttpServletRequest request, JoinPoint joinPoint) {
String httpMethod = request.getMethod(); String httpMethod = request.getMethod();
String params = ""; StringBuilder params = new StringBuilder();
if ("POST".equals(httpMethod) || "PUT".equals(httpMethod) || "PATCH".equals(httpMethod)) { List<String> list = Arrays.asList("POST","PUT","PATCH");
if (list.contains(httpMethod)) {
Object[] paramsArray = joinPoint.getArgs(); Object[] paramsArray = joinPoint.getArgs();
// java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false) // java.lang.IllegalStateException: It is illegal to call this method if the current request is not in asynchronous mode (i.e. isAsyncStarted() returns false)
// https://my.oschina.net/mengzhang6/blog/2395893 // https://my.oschina.net/mengzhang6/blog/2395893
@@ -168,7 +171,7 @@ public class AutoLogAspect {
} }
//update-begin-author:taoyan date:20200724 for:日志数据太长的直接过滤掉 //update-begin-author:taoyan date:20200724 for:日志数据太长的直接过滤掉
PropertyFilter profilter = (o, name, value) -> value == null || value.toString().length() <= 500; PropertyFilter profilter = (o, name, value) -> value == null || value.toString().length() <= 500;
params = JSON.toJSONString(arguments, profilter); params = new StringBuilder(JSON.toJSONString(arguments, profilter));
//update-end-author:taoyan date:20200724 for:日志数据太长的直接过滤掉 //update-end-author:taoyan date:20200724 for:日志数据太长的直接过滤掉
} else { } else {
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); MethodSignature signature = (MethodSignature) joinPoint.getSignature();
@@ -180,11 +183,11 @@ public class AutoLogAspect {
String[] paramNames = u.getParameterNames(method); String[] paramNames = u.getParameterNames(method);
if (args != null && paramNames != null) { if (args != null && paramNames != null) {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
params += " " + paramNames[i] + ": " + args[i]; params.append(" ").append(paramNames[i]).append(": ").append(args[i]);
} }
} }
} }
return params; return params.toString();
} }
/** /**