|
@@ -1,9 +1,7 @@
|
|
|
package cn.com.qmth.examcloud.web.interceptor;
|
|
|
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Properties;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
@@ -17,17 +15,13 @@ import com.googlecode.aviator.AviatorEvaluator;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLog;
|
|
|
import cn.com.qmth.examcloud.commons.logging.ExamCloudLogFactory;
|
|
|
-import cn.com.qmth.examcloud.commons.util.PathUtil;
|
|
|
import cn.com.qmth.examcloud.commons.util.PropertiesUtil;
|
|
|
import cn.com.qmth.examcloud.commons.util.Util;
|
|
|
import cn.com.qmth.examcloud.web.actuator.ApiStatusInfo;
|
|
|
-import cn.com.qmth.examcloud.web.actuator.ApiStatusInfoCollector;
|
|
|
-import cn.com.qmth.examcloud.web.actuator.ReportInfo;
|
|
|
-import cn.com.qmth.examcloud.web.actuator.ReportorHolder;
|
|
|
+import cn.com.qmth.examcloud.web.actuator.ApiStatusInfoHolder;
|
|
|
import cn.com.qmth.examcloud.web.enums.HttpServletRequestAttribute;
|
|
|
import cn.com.qmth.examcloud.web.support.ApiInfo;
|
|
|
import cn.com.qmth.examcloud.web.support.ServletUtil;
|
|
|
-import cn.com.qmth.examcloud.web.support.SpringContextHolder;
|
|
|
import cn.com.qmth.examcloud.web.support.StatusResponse;
|
|
|
|
|
|
/**
|
|
@@ -42,39 +36,10 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
|
|
|
private static final ExamCloudLog LOG = ExamCloudLogFactory
|
|
|
.getLog(ApiFlowLimitedInterceptor.class);
|
|
|
|
|
|
- private static Map<String, ApiStatusInfo> apiInfoMap = Maps.newHashMap();
|
|
|
-
|
|
|
private static Properties props = new Properties();
|
|
|
|
|
|
static {
|
|
|
|
|
|
- new Thread(new Runnable() {
|
|
|
- @Override
|
|
|
- public void run() {
|
|
|
- Util.sleep(10);
|
|
|
- while (true) {
|
|
|
- try {
|
|
|
- ReportorHolder.getApiDataReportor().report();
|
|
|
- List<ReportInfo> reportInfoList = ReportorHolder.getApiDataReportor()
|
|
|
- .getReportInfoList();
|
|
|
-
|
|
|
- ReportInfo reportInfo = reportInfoList.get(0);
|
|
|
- ApiStatusInfoCollector apiStatusInfoCollector = SpringContextHolder
|
|
|
- .getBean(ApiStatusInfoCollector.class);
|
|
|
- List<ApiStatusInfo> list = apiStatusInfoCollector.collect(reportInfo);
|
|
|
-
|
|
|
- Map<String, ApiStatusInfo> newApiInfoMap = list.stream()
|
|
|
- .collect(Collectors.toMap(ApiStatusInfo::getMapping, info -> info));
|
|
|
-
|
|
|
- apiInfoMap = newApiInfoMap;
|
|
|
-
|
|
|
- } catch (Exception e) {
|
|
|
- LOG.error("fail to refresh API status.", e);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }).start();
|
|
|
-
|
|
|
new Thread(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
@@ -83,8 +48,7 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
|
|
|
try {
|
|
|
Properties newProps = new Properties();
|
|
|
|
|
|
- PropertiesUtil.loadFromResource(
|
|
|
- PathUtil.getResoucePath("limited.properties"), newProps);
|
|
|
+ PropertiesUtil.loadFromResource("limited.properties", newProps);
|
|
|
|
|
|
props = newProps;
|
|
|
|
|
@@ -111,7 +75,7 @@ public class ApiFlowLimitedInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
ApiStatusInfo apiStatusInfo = null;
|
|
|
try {
|
|
|
- apiStatusInfo = apiInfoMap.get(apiInfo.getMapping());
|
|
|
+ apiStatusInfo = ApiStatusInfoHolder.getApiStatusInfo(apiInfo.getMapping());
|
|
|
} catch (Exception e) {
|
|
|
// ignore
|
|
|
}
|