Commit ca89c8d4 authored by yanzg's avatar yanzg

接口文档的支持

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