Class HttpClientFactory

java.lang.Object
cloud.opencode.base.oauth2.http.HttpClientFactory

public final class HttpClientFactory extends Object
HTTP Client Factory HTTP 客户端工厂

Factory for creating OAuth2 HTTP clients.

用于创建 OAuth2 HTTP 客户端的工厂。

Features | 主要功能:

  • Create HTTP clients with default settings - 使用默认设置创建 HTTP 客户端
  • Create HTTP clients with custom timeouts - 使用自定义超时创建 HTTP 客户端
  • Create HTTP clients from config - 从配置创建 HTTP 客户端
  • Shared client instance support - 共享客户端实例支持

Usage Examples | 使用示例:

// Create with defaults
OAuth2HttpClient client = HttpClientFactory.create();

// Create with custom timeouts
OAuth2HttpClient client = HttpClientFactory.create(
    Duration.ofSeconds(5),   // connect timeout
    Duration.ofSeconds(30)   // read timeout
);

// Create from config
OAuth2HttpClient client = HttpClientFactory.create(config);

// Get shared instance
OAuth2HttpClient shared = HttpClientFactory.shared();

Thread Safety | 线程安全:

This class is thread-safe.

此类是线程安全的。

Since:
JDK 25, opencode-base-oauth2 V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Field Details

    • DEFAULT_CONNECT_TIMEOUT

      public static final Duration DEFAULT_CONNECT_TIMEOUT
      Default connect timeout 默认连接超时
    • DEFAULT_READ_TIMEOUT

      public static final Duration DEFAULT_READ_TIMEOUT
      Default read timeout 默认读取超时
  • Method Details

    • create

      public static OAuth2HttpClient create()
      Create an HTTP client with default settings 使用默认设置创建 HTTP 客户端
      Returns:
      the HTTP client | HTTP 客户端
    • create

      public static OAuth2HttpClient create(Duration connectTimeout, Duration readTimeout)
      Create an HTTP client with custom timeouts 使用自定义超时创建 HTTP 客户端
      Parameters:
      connectTimeout - the connection timeout | 连接超时
      readTimeout - the read timeout | 读取超时
      Returns:
      the HTTP client | HTTP 客户端
    • create

      public static OAuth2HttpClient create(OAuth2Config config)
      Create an HTTP client from OAuth2 configuration 从 OAuth2 配置创建 HTTP 客户端
      Parameters:
      config - the OAuth2 configuration | OAuth2 配置
      Returns:
      the HTTP client | HTTP 客户端
    • shared

      public static OAuth2HttpClient shared()
      Get the shared HTTP client instance 获取共享的 HTTP 客户端实例

      This returns a singleton HTTP client that can be safely shared across multiple OAuth2 clients. The shared client uses default timeouts.

      Note: The shared client should not be closed as it may be used by other components.

      Returns:
      the shared HTTP client | 共享的 HTTP 客户端
    • builder

      public static HttpClientFactory.Builder builder()
      Create a builder for customizing the HTTP client 创建用于自定义 HTTP 客户端的构建器
      Returns:
      the builder | 构建器