Class InterceptorContext
java.lang.Object
io.leandev.appfuse.http.logging.InterceptorContext
攔截器上下文
提供在攔截器鏈中傳遞資料的機制,每個 HTTP 請求都有獨立的上下文實例。
使用場景
- 在 beforeRequest 記錄開始時間,在 afterResponse 計算耗時
- 在不同攔截器之間傳遞資料
- 記錄請求的唯一識別碼
- 累計重試次數
使用範例
// beforeRequest
context.put("startTime", System.currentTimeMillis());
context.incrementRetryCount();
// afterResponse
long startTime = (Long) context.get("startTime");
long duration = System.currentTimeMillis() - startTime;
int retries = context.getRetryCount();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()清空所有屬性boolean檢查是否包含指定屬性取得自訂屬性<T> T取得自訂屬性(泛型版本)取得請求的唯一識別碼int取得重試次數void增加重試次數void設定自訂屬性void移除指定屬性
-
Constructor Details
-
InterceptorContext
public InterceptorContext()建立新的攔截器上下文
-
-
Method Details
-
getRequestId
-
getRetryCount
public int getRetryCount()取得重試次數- Returns:
- 重試次數
-
incrementRetryCount
public void incrementRetryCount()增加重試次數 -
put
-
get
-
get
-
contains
-
remove
-
clear
public void clear()清空所有屬性
-