Commit 97dd0710 authored by yanzg's avatar yanzg

异常处理显示

parent 88b98773
package com.yanzuoguang.cloud.aop;
import com.alibaba.fastjson.JSON;
import com.yanzuoguang.cloud.CloudContans;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper;
......@@ -91,17 +90,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
logInterVo.setLogSources(applicationName);
//请求URL
logInterVo.setInterUrl(url);
List<Object> para = new ArrayList<>();
for (Object item : joinPoint.getArgs()) {
if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) {
continue;
}
para.add(item);
}
Object paraTo = para;
if (para.size() == 1) {
paraTo = para.get(0);
}
Object paraTo = getFirstDataParameter(joinPoint.getArgs());
//请求参数
logInterVo.setContent(JSON.toJSONString(paraTo));
//返回参数
......@@ -110,6 +99,37 @@ public class BaseRequestAspect implements ThreadNext.Next {
return logInterVo;
}
/**
* 获取请求的参数
*
* @param args
* @return
*/
protected Object getFirstDataParameter(Object[] args) {
List<Object> para = getDataParameters(args);
Object paraTo = para;
if (para.size() == 1) {
paraTo = para.get(0);
}
return paraTo;
}
/**
* 获取数据参数
* @param args
* @return
*/
protected List<Object> getDataParameters(Object[] args) {
List<Object> para = new ArrayList<>();
for (Object item : args) {
if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) {
continue;
}
para.add(item);
}
return para;
}
/**
* 获取JSON,当Json过长时,截断
*
......@@ -147,7 +167,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
try {
String name = joinPoint.getSignature().getName();
Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s",
tag, name, this.getMaxString(JsonHelper.serialize(joinPoint.getArgs())));
tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs()))));
} catch (Exception ex) {
ex.printStackTrace();
}
......
......@@ -16,10 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
/**
* LogsAspect(接口请求日志切面)
......@@ -148,9 +147,8 @@ public class WebAspect extends BaseRequestAspect {
* @throws Throwable
*/
private Object executeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
boolean dataArgs = joinPoint.getArgs().length != 1
|| joinPoint.getArgs().length == 1 &&
(joinPoint.getArgs()[0] instanceof ServletResponse || joinPoint.getArgs()[0] instanceof ServletRequest);
List<Object> dataParas = this.getDataParameters(joinPoint.getArgs());
boolean dataArgs = dataParas.isEmpty();
Method method = getMethod(joinPoint);
boolean isUrl = false;
if (!StringHelper.isEmpty(reqUrl)) {
......@@ -166,7 +164,7 @@ public class WebAspect extends BaseRequestAspect {
return joinPoint.proceed();
} else {
// 获取请求编号
Object firstArgs = joinPoint.getArgs().length > 0 ? joinPoint.getArgs()[0] : null;
Object firstArgs = dataParas.size() > 0 ? dataParas.get(0) : null;
String reqId = StringHelper.md5(JsonHelper.serialize(firstArgs));
String reqFull = StringHelper.getId(reqId, HttpAspectUtil.getHttpRequestUrl());
RequestCacheResult req = cacheResult.get(reqFull, new RequestCacheResult(reqFull));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment