|
@@ -1,7 +1,6 @@
|
|
|
package cn.com.qmth.examcloud.web.support;
|
|
|
|
|
|
import cn.com.qmth.examcloud.api.commons.exchange.BaseResponse;
|
|
|
-import cn.com.qmth.examcloud.api.commons.exchange.JsonSerializable;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
import cn.com.qmth.examcloud.commons.util.JsonMapper;
|
|
@@ -10,6 +9,7 @@ import cn.com.qmth.examcloud.commons.util.ThreadLocalUtil;
|
|
|
import cn.com.qmth.examcloud.web.config.LogProperties;
|
|
|
import cn.com.qmth.examcloud.web.enums.HttpServletRequestAttribute;
|
|
|
import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
+import org.apache.commons.collections.MapUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
@@ -18,10 +18,10 @@ import org.aspectj.lang.annotation.Pointcut;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.Serializable;
|
|
|
import java.util.Collection;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -101,47 +101,40 @@ public class ControllerAspect {
|
|
|
if (INTERFACE_LOG.isInfoEnabled()) {
|
|
|
StringBuilder params = new StringBuilder();
|
|
|
|
|
|
- if (args != null) {
|
|
|
- if (args.length == 0) {
|
|
|
- Map<String, String[]> paramMaps = request.getParameterMap();
|
|
|
- for (Map.Entry<String, String[]> entry : paramMaps.entrySet()) {
|
|
|
- String name = entry.getKey();
|
|
|
- String[] values = entry.getValue();
|
|
|
- params.append("&").append(name).append("=");
|
|
|
- if (ArrayUtils.isNotEmpty(values)) {
|
|
|
- if (name.toLowerCase().indexOf(excludeFields[0]) >= 0) {
|
|
|
- params.append("***");
|
|
|
- } else {
|
|
|
- params.append(values[0]);
|
|
|
- }
|
|
|
- }
|
|
|
+ // api method params
|
|
|
+ if (ArrayUtils.isNotEmpty(args)) {
|
|
|
+ params.append(" methodParams: ");
|
|
|
+ for (int i = 0; i < args.length; i++) {
|
|
|
+ Object curArg = args[i];
|
|
|
+ String content = this.parseContent(curArg);
|
|
|
+ params.append(content);
|
|
|
+
|
|
|
+ if (i < args.length - 1) {
|
|
|
+ params.append(" | ");
|
|
|
}
|
|
|
- } else {
|
|
|
- for (int i = 0; i < args.length; i++) {
|
|
|
- Object curArg = args[i];
|
|
|
- if (curArg == null) {
|
|
|
- params.append("null");
|
|
|
- } else if (ObjectUtil.isBaseDataType(curArg.getClass())) {
|
|
|
- params.append(curArg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // api url params
|
|
|
+ Map<String, String[]> paramMaps = request.getParameterMap();
|
|
|
+ if (MapUtils.isNotEmpty(paramMaps)) {
|
|
|
+ params.append(" urlParams: ");
|
|
|
+ for (Map.Entry<String, String[]> entry : paramMaps.entrySet()) {
|
|
|
+ String name = entry.getKey();
|
|
|
+ String[] values = entry.getValue();
|
|
|
+ params.append("&").append(name).append("=");
|
|
|
+
|
|
|
+ if (ArrayUtils.isNotEmpty(values)) {
|
|
|
+ if (name.toLowerCase().indexOf(excludeFields[0]) >= 0) {
|
|
|
+ params.append("***");
|
|
|
} else {
|
|
|
- String content = this.parseContent(curArg);
|
|
|
- if (content == null) {
|
|
|
- content = "...";
|
|
|
- } else {
|
|
|
- if (content.length() > logProperties.getResponseLogJsonMaxSize()) {
|
|
|
- content = "content too large...";
|
|
|
- }
|
|
|
- }
|
|
|
- params.append(content);
|
|
|
- }
|
|
|
- if (i < args.length - 1) {
|
|
|
- params.append(" | ");
|
|
|
+ params.append(values[0]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- INTERFACE_LOG.info(String.format("[ControllerAspect][request][%s] - %s, params = %s", method, path, params.toString()));
|
|
|
+ INTERFACE_LOG.info(String.format("[ControllerAspect][request][%s] - %s %s", method, path, params.toString()));
|
|
|
}
|
|
|
|
|
|
Object ret;
|
|
@@ -185,55 +178,17 @@ public class ControllerAspect {
|
|
|
|
|
|
if (INTERFACE_LOG.isDebugEnabled() && logProperties.isNormalResponseLogEnable()) {
|
|
|
if (ret == null) {
|
|
|
- INTERFACE_LOG.debug("[ControllerAspect] status = 200, responseMsg = void");
|
|
|
+ INTERFACE_LOG.debug("[ControllerAspect] status = ok, responseMsg = void");
|
|
|
} else if (ret instanceof ResponseEntity) {
|
|
|
ResponseEntity<?> re = (ResponseEntity<?>) ret;
|
|
|
Object body = re.getBody();
|
|
|
|
|
|
- String content = null;
|
|
|
- if (body != null) {
|
|
|
- boolean jsonSerializable = false;
|
|
|
- if (body instanceof Collection) {
|
|
|
- jsonSerializable = true;
|
|
|
- } else if (body instanceof Map) {
|
|
|
- jsonSerializable = true;
|
|
|
- } else if (body instanceof String) {
|
|
|
- jsonSerializable = true;
|
|
|
- } else if (body instanceof JsonSerializable) {
|
|
|
- jsonSerializable = true;
|
|
|
- }
|
|
|
- if (jsonSerializable) {
|
|
|
- content = this.parseContent(body);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (content == null) {
|
|
|
- content = "...";
|
|
|
- } else {
|
|
|
- if (content.length() > logProperties.getResponseLogJsonMaxSize()) {
|
|
|
- content = "content too large...";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ String content = this.parseContent(body);
|
|
|
INTERFACE_LOG.debug(String.format("[ControllerAspect] status = %s, responseMsg = %s",
|
|
|
re.getStatusCodeValue(), content));
|
|
|
} else {
|
|
|
- String content;
|
|
|
- if (ObjectUtil.isBaseDataType(ret.getClass())) {
|
|
|
- content = ret.toString();
|
|
|
- } else {
|
|
|
- content = this.parseContent(ret);
|
|
|
- }
|
|
|
-
|
|
|
- if (content == null) {
|
|
|
- content = "...";
|
|
|
- } else {
|
|
|
- if (content.length() > logProperties.getResponseLogJsonMaxSize()) {
|
|
|
- content = "content too large...";
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- INTERFACE_LOG.debug(String.format("[ControllerAspect] status = 200, responseMsg = %s", content));
|
|
|
+ String content = this.parseContent(ret);
|
|
|
+ INTERFACE_LOG.debug(String.format("[ControllerAspect] status = ok, responseMsg = %s", content));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -246,17 +201,50 @@ public class ControllerAspect {
|
|
|
}
|
|
|
|
|
|
private String parseContent(Object obj) {
|
|
|
- try {
|
|
|
- if (obj instanceof MultipartFile) {
|
|
|
- return ((MultipartFile) obj).getOriginalFilename();
|
|
|
+ if (obj == null) {
|
|
|
+ // content empty...
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isBaseDataType(obj.getClass()) || obj instanceof String) {
|
|
|
+ return obj.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean jsonEnable = false;
|
|
|
+ if (obj instanceof Collection) {
|
|
|
+ jsonEnable = true;
|
|
|
+ } else if (obj instanceof Map) {
|
|
|
+ jsonEnable = true;
|
|
|
+ } else if (obj instanceof Serializable) {
|
|
|
+ String classPath = obj.getClass().getName();
|
|
|
+ if (classPath.toLowerCase().startsWith("cn.com.qmth")) {
|
|
|
+ jsonEnable = true;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // return new JsonMapper().toJson(obj);
|
|
|
+ if (!jsonEnable) {
|
|
|
+ // content ignore...
|
|
|
+ return "...";
|
|
|
+ }
|
|
|
+
|
|
|
+ String content = null;
|
|
|
+ try {
|
|
|
+ // content to json
|
|
|
+ content = new JsonMapper().toJson(obj);
|
|
|
} catch (Exception e) {
|
|
|
INTERFACE_LOG.warn("[ControllerAspect] parseContent " + e.getMessage());
|
|
|
}
|
|
|
|
|
|
- return null;
|
|
|
+ if (content == null) {
|
|
|
+ return "......";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (content.length() > logProperties.getResponseLogJsonMaxSize()) {
|
|
|
+ // content too large...
|
|
|
+ return content.substring(0, logProperties.getResponseLogJsonMaxSize()) + " [MORE...]";
|
|
|
+ }
|
|
|
+
|
|
|
+ return content;
|
|
|
}
|
|
|
|
|
|
}
|