Commit ca89c8d4 authored by yanzg's avatar yanzg

接口文档的支持

parent 1b0bf04f
......@@ -49,6 +49,8 @@ public class WebAspect extends BaseRequestAspect {
public void webAspect() {
}
/**
* 执行环形切面
*
......@@ -64,9 +66,10 @@ public class WebAspect extends BaseRequestAspect {
Exception ex = null;
Ref<Boolean> flag = new Ref<>(false);
boolean isGateWay = isGateWay();
boolean isInit = false;
try {
if (!isGateWay) {
tokenServiceCall.tokenInit();
isInit = tokenServiceCall.tokenInit();
}
result = executeMethod(joinPoint);
if (!isGateWay) {
......@@ -82,10 +85,12 @@ public class WebAspect extends BaseRequestAspect {
throw e;
}
} finally {
if (!isGateWay) {
tokenFinish(flag);
if(isInit){
if (!isGateWay) {
tokenFinish(flag);
}
TokenHelper.remove();
}
TokenHelper.remove();
responseLog(clear, TAG, HttpAspectUtil.getHttpRequestUrl(), joinPoint, start, result, ex);
}
}
......
......@@ -12,7 +12,7 @@ public interface TokenService extends TokenLoad {
/**
* 初始化token
*/
boolean tokenInit();
void tokenInit();
/**
* 结束token
......
......@@ -3,7 +3,10 @@ package com.yanzuoguang.cloud.service;
import com.yanzuoguang.token.TokenData;
import com.yanzuoguang.token.TokenHelper;
import com.yanzuoguang.token.TokenLoad;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
import com.yanzuoguang.util.thread.ThreadHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
......@@ -23,6 +26,8 @@ public class TokenServiceCall implements TokenLoad {
private int flagCount = 3;
private MemoryCache<Boolean> countCache = new MemoryCache<>();
public TokenServiceCall() {
TokenHelper.setTokenLoad(this);
}
......@@ -46,12 +51,17 @@ public class TokenServiceCall implements TokenLoad {
/**
* 请求时初始化token
*/
public void tokenInit() {
public boolean tokenInit() {
init();
if (tokenService == null) {
return;
return false;
}
if (isHave()) {
return false;
}
tokenService.tokenInit();
setHave();
return true;
}
/**
......@@ -63,6 +73,7 @@ public class TokenServiceCall implements TokenLoad {
return;
}
tokenService.tokenFinish();
removeHave();
}
/**
......@@ -79,4 +90,19 @@ public class TokenServiceCall implements TokenLoad {
}
return tokenService.load(token);
}
private boolean isHave() {
String id = StringHelper.toString(Thread.currentThread().getId());
return StringHelper.toBoolean(countCache.get(id));
}
private void setHave() {
String id = StringHelper.toString(Thread.currentThread().getId());
countCache.put(id, true);
}
private void removeHave() {
String id = StringHelper.toString(Thread.currentThread().getId());
countCache.remove(id);
}
}
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