deason 5 жил өмнө
parent
commit
935377a402

+ 11 - 8
src/main/java/cn/com/qmth/examcloud/app/core/utils/HttpUtils.java

@@ -31,8 +31,11 @@ public class HttpUtils {
     private static Logger log = LoggerFactory.getLogger(HttpUtils.class);
 
     public static String getRandomTraceId() {
-        //return ThreadUtils.getTraceID();
-        return UUID.randomUUID().toString().replace("-", "");
+        String traceId = ThreadUtils.getTraceID();
+        if (StringUtils.isBlank(traceId)) {
+            traceId = UUID.randomUUID().toString().replace("-", "");
+        }
+        return traceId;
     }
 
     public static Result<String> doGet(String requestUrl, String key, String token) throws Exception {
@@ -49,7 +52,7 @@ public class HttpUtils {
                 .build();
 
         //执行请求
-        log.info("[TRACE_ID] " + traceId + " [GET] " + requestUrl);
+        log.info("[GET] " + requestUrl);
         return call(request, traceId);
     }
 
@@ -67,7 +70,7 @@ public class HttpUtils {
                 .build();
 
         //执行请求
-        log.info("[TRACE_ID] " + traceId + " [POST] " + requestUrl);
+        log.info("[POST] " + requestUrl);
         return call(request, traceId);
     }
 
@@ -85,7 +88,7 @@ public class HttpUtils {
                 .build();
 
         //执行请求
-        log.info("[TRACE_ID] " + traceId + " [PUT] " + requestUrl);
+        log.info("[PUT] " + requestUrl);
         return call(request, traceId);
     }
 
@@ -94,16 +97,16 @@ public class HttpUtils {
         try {
             response = HttpClientBuilder.getClient().newCall(request).execute();
         } catch (ConnectException e) {
-            log.error("[TRACE_ID] " + traceId + " [ConnectException] " + e.getMessage());
+            log.error("[ConnectException] " + e.getMessage());
             return new Result<>().error("服务访问失败!");
         }
 
         String bodyStr = response.body().string();
         if (response.isSuccessful()) {
-            log.info("[TRACE_ID] " + traceId + "[Response] is success!");
+            log.info("[Response] is success!");
             return new Result().success(bodyStr);
         } else {
-            log.warn("[TRACE_ID] " + traceId + "[Response] is fail! body:" + bodyStr);
+            log.warn("[Response] is fail! body:" + bodyStr);
             ResBody body = new JsonMapper().fromJson(bodyStr, ResBody.class);
             if (body != null && body.getCode() != null) {
                 if (Constants.CODE_403.equals(body.getCode())) {