Class BaseDifyServerToken

java.lang.Object
io.github.guoshiqiufeng.dify.server.client.BaseDifyServerToken
Direct Known Subclasses:
DifyServerTokenDefault, DifyServerTokenRedis

public abstract class BaseDifyServerToken extends Object
Since:
2025/4/9 13:28
Version:
1.0
Author:
yanghq
  • Field Details

    • MAX_RETRY_ATTEMPTS

      protected static final int MAX_RETRY_ATTEMPTS
      最大重试次数
      See Also:
  • Constructor Details

    • BaseDifyServerToken

      public BaseDifyServerToken()
  • Method Details

    • addAuthorizationHeader

      public abstract void addAuthorizationHeader(org.springframework.http.HttpHeaders headers, DifyServerClient difyServerClient)
      Abstract method to add authorization header to HTTP request.
      Parameters:
      headers - HTTP headers to be populated with authorization information
      difyServerClient - client instance containing necessary configuration
    • executeWithRetry

      public <T> T executeWithRetry(RequestSupplier<T> supplier, DifyServerClient difyServerClient)
      Executes the given request supplier with automatic retry mechanism. Will retry when encountering 401 Unauthorized errors, up to MAX_RETRY_ATTEMPTS times.
      Type Parameters:
      T - type of the response object
      Parameters:
      supplier - request execution supplier that provides the result
      difyServerClient - client instance for token refresh operations
      Returns:
      result from the successful request execution
      Throws:
      RuntimeException - when max retry attempts are exhausted
      Exception - when non-retryable errors occur