|
|
|
@ -6,7 +6,6 @@ import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import org.apache.commons.lang3.time.StopWatch;
|
|
|
|
import org.apache.commons.lang3.time.StopWatch;
|
|
|
|
import org.dromara.common.core.utils.SpringUtils;
|
|
|
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
import org.dromara.common.json.utils.JsonUtils;
|
|
|
|
import org.dromara.common.json.utils.JsonUtils;
|
|
|
|
import org.dromara.common.web.filter.RepeatedlyRequestWrapper;
|
|
|
|
import org.dromara.common.web.filter.RepeatedlyRequestWrapper;
|
|
|
|
@ -19,7 +18,6 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* web的调用时间统计拦截器
|
|
|
|
* web的调用时间统计拦截器
|
|
|
|
* dev环境有效
|
|
|
|
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Lion Li
|
|
|
|
* @author Lion Li
|
|
|
|
* @since 3.3.0
|
|
|
|
* @since 3.3.0
|
|
|
|
@ -27,13 +25,10 @@ import java.util.Map;
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
|
public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
|
|
|
|
|
|
private final String prodProfile = "prod";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final static ThreadLocal<StopWatch> KEY_CACHE = new ThreadLocal<>();
|
|
|
|
private final static ThreadLocal<StopWatch> KEY_CACHE = new ThreadLocal<>();
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
|
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
|
|
|
if (!prodProfile.equals(SpringUtils.getActiveProfile())) {
|
|
|
|
|
|
|
|
String url = request.getMethod() + " " + request.getRequestURI();
|
|
|
|
String url = request.getMethod() + " " + request.getRequestURI();
|
|
|
|
|
|
|
|
|
|
|
|
// 打印请求参数
|
|
|
|
// 打印请求参数
|
|
|
|
@ -57,7 +52,7 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
|
StopWatch stopWatch = new StopWatch();
|
|
|
|
KEY_CACHE.set(stopWatch);
|
|
|
|
KEY_CACHE.set(stopWatch);
|
|
|
|
stopWatch.start();
|
|
|
|
stopWatch.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,13 +63,11 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
|
|
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
|
|
|
if (!prodProfile.equals(SpringUtils.getActiveProfile())) {
|
|
|
|
|
|
|
|
StopWatch stopWatch = KEY_CACHE.get();
|
|
|
|
StopWatch stopWatch = KEY_CACHE.get();
|
|
|
|
stopWatch.stop();
|
|
|
|
stopWatch.stop();
|
|
|
|
log.info("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
|
|
|
|
log.info("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
|
|
|
|
KEY_CACHE.remove();
|
|
|
|
KEY_CACHE.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 判断本次请求的数据类型是否为json
|
|
|
|
* 判断本次请求的数据类型是否为json
|
|
|
|
|