From 92324cb0d60d52275fe9b96355b18392389e113d Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Thu, 16 Oct 2025 11:51:59 +0800
Subject: [PATCH] 优化
---
ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java | 23 ++++++++++++++++-------
1 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java b/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java
index 207fbce..f20837b 100644
--- a/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java
+++ b/ard-work/src/main/java/com/ard/work/component/forest/TokenInterceptor.java
@@ -3,6 +3,7 @@
import com.ard.work.domain.receiver.AccessTokenReceiver;
import com.ard.work.service.IArdServerInfoService;
import com.dtflys.forest.http.ForestRequest;
+import com.dtflys.forest.interceptor.ForestInterceptor;
import com.dtflys.forest.interceptor.Interceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -10,7 +11,7 @@
@Component
@Slf4j
-public class TokenInterceptor<T> implements Interceptor<T> {
+public class TokenInterceptor implements ForestInterceptor {
@Resource
private IArdServerInfoService ardServerService;
@@ -21,11 +22,19 @@
*/
@Override
public boolean beforeExecute(ForestRequest req) {
- log.debug("invoke Simple beforeExecute");
- String serverId = (String) req.getVariableValue("serverId");
- AccessTokenReceiver accessToken = ardServerService.getAccessToken(serverId);
- req.addHeader("x-cid", accessToken.getCompanyId());
- req.addHeader("x-token", accessToken.getAccessToken());
- return true; // 继续执行请求返回true
+ try {
+ String serverId = (String) req.getVariableValue("serverId");
+ AccessTokenReceiver accessToken = ardServerService.getAccessToken(serverId);
+ if (accessToken == null) {
+ log.warn("AccessToken 为 null, serverId={}", serverId);
+ return false; // 阻止请求继续
+ }
+ req.addHeader("x-cid", accessToken.getCompanyId());
+ req.addHeader("x-token", accessToken.getAccessToken());
+ } catch (Exception e) {
+ log.error("TokenInterceptor 处理异常:{}", e.getMessage());
+ return false;
+ }
+ return true;
}
}
\ No newline at end of file
--
Gitblit v1.9.3