diff --git a/src/main/java/org/anyin/gitee/shiro/advisor/ApiMessageAdvisor.java b/src/main/java/org/anyin/gitee/shiro/advisor/ApiMessageAdvisor.java index dfd0cd7..0edeccc 100644 --- a/src/main/java/org/anyin/gitee/shiro/advisor/ApiMessageAdvisor.java +++ b/src/main/java/org/anyin/gitee/shiro/advisor/ApiMessageAdvisor.java @@ -120,21 +120,21 @@ public class ApiMessageAdvisor { * @return RequestId */ private String getRequestId(){ + // 因为如果有网关,则一般会从网关传递过来,所以优先从header头获取 ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - if(attributes == null || !StringUtils.hasText(attributes.getRequest().getHeader("x-request-id"))) { - RequestIdUtils.generateRequestId(); - return RequestIdUtils.getRequestId().toString(); + if(attributes != null && StringUtils.hasText(attributes.getRequest().getHeader("x-request-id"))) { + HttpServletRequest request = attributes.getRequest(); + String requestId = request.getHeader("x-request-id"); + UUID uuid = UUID.fromString(requestId); + RequestIdUtils.generateRequestId(uuid); + return requestId; } UUID existUUID = RequestIdUtils.getRequestId(); if(existUUID != null){ return existUUID.toString(); } - // 因为如果有网关,则一般会从网关传递过来,所以优先从header头获取 - HttpServletRequest request = attributes.getRequest(); - String requestId = request.getHeader("x-request-id"); - UUID uuid = UUID.fromString(requestId); - RequestIdUtils.generateRequestId(uuid); - return requestId; + RequestIdUtils.generateRequestId(); + return RequestIdUtils.getRequestId().toString(); } /** diff --git a/src/main/java/org/anyin/gitee/shiro/base/MdcExecutor.java b/src/main/java/org/anyin/gitee/shiro/base/MdcExecutor.java index 26f4502..93ab501 100644 --- a/src/main/java/org/anyin/gitee/shiro/base/MdcExecutor.java +++ b/src/main/java/org/anyin/gitee/shiro/base/MdcExecutor.java @@ -5,13 +5,10 @@ import org.slf4j.MDC; import java.util.concurrent.Executor; public class MdcExecutor implements Executor { - private Executor executor; - public MdcExecutor(Executor executor) { this.executor = executor; } - @Override public void execute(Runnable command) { final String requestId = MDC.get("REQUEST_ID");