Commit 602a93df authored by yanzg's avatar yanzg

接口文档的支持

parent 3ec864d9
......@@ -60,11 +60,6 @@ public class BaseRequestAspect implements ThreadNext.Next {
*/
protected volatile LinkedBlockingQueue<LogVo> cache = new LinkedBlockingQueue<LogVo>();
/**
* 缓存的每次请求的结果
*/
protected MemoryCache<RequestCacheResult> cacheResult = new MemoryCache<>(cacheTime);
public BaseRequestAspect() {
ThreadNext.start(this, "save log error");
}
......@@ -263,10 +258,14 @@ public class BaseRequestAspect implements ThreadNext.Next {
while (cache.size() > 0) {
LogVo item = cache.poll();
if (item != null) {
try {
if (logFeign == null) {
logFeign = context.getBean(LogFeign.class);
}
logFeign.save(item);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
return true;
......
......@@ -36,9 +36,6 @@ public class WebAspect extends BaseRequestAspect {
@Autowired
private TokenServiceCall tokenServiceCall;
@Value("${yzg.reqUrl:}")
private String reqUrl;
@Value("${yzg.gateway:^.*gateway.*$}")
private String gateWay;
......@@ -58,22 +55,22 @@ public class WebAspect extends BaseRequestAspect {
*/
@Around(value = "webAspect()")
public Object requestWebAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object result = null;
boolean isGateWay = isGateWay();
if (isGateWay) {
result = executeMethod(joinPoint);
return result;
}
boolean clear = requestLogInit();
// 用户数据库记录
long start = requestLog(TAG, joinPoint);
Object result = null;
Exception ex = null;
Ref<Boolean> flag = new Ref<>(false);
boolean isGateWay = isGateWay();
boolean isInit = false;
try {
if (!isGateWay) {
isInit = tokenServiceCall.tokenInit();
}
result = executeMethod(joinPoint);
if (!isGateWay) {
tokenFinish(flag);
}
return result;
} catch (Exception e) {
ex = e;
......@@ -85,9 +82,7 @@ public class WebAspect extends BaseRequestAspect {
}
} finally {
if (isInit) {
if (!isGateWay) {
tokenFinish(flag);
}
TokenHelper.remove();
}
responseLog(clear, TAG, HttpAspectUtil.getHttpRequestUrl(), joinPoint, start, result, ex);
......@@ -153,44 +148,6 @@ public class WebAspect extends BaseRequestAspect {
* @throws Throwable
*/
private Object executeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
List<Object> dataParas = this.getDataParameters(joinPoint.getArgs());
boolean dataArgs = dataParas.isEmpty();
Method method = getMethod(joinPoint);
boolean isUrl = false;
if (!StringHelper.isEmpty(reqUrl)) {
String[] urls = reqUrl.split(",");
for (String url : urls) {
if (method.getName().matches(url)) {
isUrl = true;
break;
}
}
}
if (dataArgs || !isUrl) {
return joinPoint.proceed();
} else {
// 获取请求编号
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));
// 缓存的键值对
if (req.getResult() == null) {
synchronized (req) {
if (req.getResult() == null) {
try {
req.setResult(joinPoint.proceed());
} catch (Exception ex) {
req.setResult(ex);
}
}
}
}
Object result = req.getResult();
if (result instanceof Throwable) {
throw (Throwable) result;
}
return result;
}
}
}
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