|
|
@@ -1,40 +1,35 @@
|
|
|
-package top.haijunit.train.config.interceptor;
|
|
|
+package top.haijunit.web.interceptor;
|
|
|
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.alibaba.ttl.TransmittableThreadLocal;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.apache.commons.lang3.time.StopWatch;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
import top.haijunit.common.utils.JsonUtils;
|
|
|
import top.haijunit.common.utils.SpringUtils;
|
|
|
-import top.haijunit.train.config.filter.RepeatedlyRequestWrapper;
|
|
|
+import top.haijunit.web.filter.RepeatedlyRequestWrapper;
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @author zhanghaijun
|
|
|
- * @date 2023/11/7 14:02
|
|
|
+ * @date 2023/11/22 18:31
|
|
|
* @description web的调用时间统计拦截器
|
|
|
*/
|
|
|
@Slf4j
|
|
|
-public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
+public class WebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
- private final String prodProfile = "prod";
|
|
|
-
|
|
|
- private final TransmittableThreadLocal<StopWatch> invokeTimeTL = new TransmittableThreadLocal<>();
|
|
|
+ private final static String PRO_FILE = "prod";
|
|
|
|
|
|
@Override
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
- if (!prodProfile.equals(SpringUtils.getActiveProfile())) {
|
|
|
+ if (!PRO_FILE.equals(SpringUtils.getActiveProfile())) {
|
|
|
String url = request.getMethod() + " " + request.getRequestURI();
|
|
|
-
|
|
|
// 打印请求参数
|
|
|
if (isJsonRequest(request)) {
|
|
|
String jsonParam = "";
|
|
|
@@ -52,10 +47,6 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
log.debug("[PLUS]开始请求 => URL[{}],无参数", url);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- StopWatch stopWatch = new StopWatch();
|
|
|
- invokeTimeTL.set(stopWatch);
|
|
|
- stopWatch.start();
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
@@ -67,12 +58,6 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
@Override
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
|
- if (!prodProfile.equals(SpringUtils.getActiveProfile())) {
|
|
|
- StopWatch stopWatch = invokeTimeTL.get();
|
|
|
- stopWatch.stop();
|
|
|
- log.debug("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
|
|
|
- invokeTimeTL.remove();
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -88,5 +73,4 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
-
|
|
|
}
|