Class OAuth2HttpClient

java.lang.Object
cloud.opencode.base.oauth2.http.OAuth2HttpClient
All Implemented Interfaces:
AutoCloseable

public class OAuth2HttpClient extends Object implements AutoCloseable
OAuth2 HTTP Client OAuth2 HTTP 客户端

HTTP client wrapper for OAuth2 operations using JDK HttpClient.

使用 JDK HttpClient 的 OAuth2 操作 HTTP 客户端包装器。

Features | 主要功能:

  • JDK HttpClient integration - JDK HttpClient 集成
  • Form URL encoded requests - 表单 URL 编码请求
  • JSON response handling - JSON 响应处理
  • Timeout configuration - 超时配置

Usage Examples | 使用示例:

// Used internally by OAuth2Client
// 由OAuth2Client内部使用
OAuth2HttpClient client = new OAuth2HttpClient(config);
String response = client.post(tokenUrl, params);

Security | 安全性:

  • Thread-safe: No - 线程安全: 否
  • Null-safe: Yes (validates inputs) - 空值安全: 是(验证输入)
Since:
JDK 25, opencode-base-oauth2 V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OAuth2HttpClient

      public OAuth2HttpClient()
      Create a new OAuth2 HTTP client with default settings 使用默认设置创建新的 OAuth2 HTTP 客户端
    • OAuth2HttpClient

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

      public OAuth2HttpClient(OAuth2Config config)
      Create a new OAuth2 HTTP client from config 从配置创建新的 OAuth2 HTTP 客户端
      Parameters:
      config - the OAuth2 config | OAuth2 配置
  • Method Details

    • postForm

      public String postForm(String url, Map<String,String> params)
      Send a POST request with form-encoded body 发送带有表单编码正文的 POST 请求
      Parameters:
      url - the URL | URL
      params - the form parameters | 表单参数
      Returns:
      the response body | 响应正文
      Throws:
      OAuth2Exception - on HTTP errors | HTTP 错误时抛出
    • postForm

      public String postForm(String url, Map<String,String> params, Map<String,String> headers)
      Send a POST request with form-encoded body and headers 发送带有表单编码正文和头的 POST 请求
      Parameters:
      url - the URL | URL
      params - the form parameters | 表单参数
      headers - additional headers | 附加头
      Returns:
      the response body | 响应正文
      Throws:
      OAuth2Exception - on HTTP errors | HTTP 错误时抛出
    • get

      public String get(String url, Map<String,String> headers)
      Send a GET request 发送 GET 请求
      Parameters:
      url - the URL | URL
      headers - the headers | 头
      Returns:
      the response body | 响应正文
      Throws:
      OAuth2Exception - on HTTP errors | HTTP 错误时抛出
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable