Class HTTPClient

java.lang.Object
org.apache.gravitino.client.HTTPClient
All Implemented Interfaces:
Closeable, AutoCloseable, RESTClient

public class HTTPClient extends Object implements RESTClient
An HttpClient for usage with the REST catalog.

This class provides functionality for making HTTP requests to a REST API and processing the corresponding responses. It supports common HTTP methods like GET, POST, PUT, DELETE, and HEAD. Additionally, it allows handling server error responses using a custom error handler.

Referred from core/src/main/java/org/apache/iceberg/rest/HTTPClient.java

  • Method Details

    • head

      public void head(String path, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP HEAD request to the specified path and processes the response.
      Specified by:
      head in interface RESTClient
      Parameters:
      path - The URL path to send the HEAD request to.
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
    • get

      public <T extends RESTResponse> T get(String path, Map<String,String> queryParams, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP GET request to the specified path and processes the response.
      Specified by:
      get in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the GET request to.
      queryParams - A map of query parameters (key-value pairs) to include in the request URL (can be null).
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      Returns:
      The response entity parsed and converted to its type T.
    • post

      public <T extends RESTResponse> T post(String path, RESTRequest body, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP POST request to the specified path with the provided request body and processes the response.
      Specified by:
      post in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the POST request to.
      body - The REST body to place in the request body.
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      Returns:
      The response entity parsed and converted to its type T.
    • post

      public <T extends RESTResponse> T post(String path, RESTRequest body, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler, Consumer<Map<String,String>> responseHeaders)
      Sends an HTTP POST request to the specified path with the provided request body and processes the response with support for response headers.
      Specified by:
      post in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the POST request to.
      body - The REST request to place in the request body.
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      responseHeaders - The consumer of the response headers for further processing.
      Returns:
      The response entity parsed and converted to its type T.
    • put

      public <T extends RESTResponse> T put(String path, RESTRequest body, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP PUT request to the specified path with the provided request body and processes the response.
      Specified by:
      put in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the PUT request to.
      body - The REST request to place in the request body.
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      Returns:
      The response entity parsed and converted to its type T.
    • put

      public <T extends RESTResponse> T put(String path, RESTRequest body, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler, Consumer<Map<String,String>> responseHeaders)
      Sends an HTTP PUT request to the specified path with the provided request body and processes the response with support for response headers.
      Specified by:
      put in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the PUT request to.
      body - The REST request to place in the request body.
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      responseHeaders - The consumer of the response headers for further processing.
      Returns:
      The response entity parsed and converted to its type T.
    • patch

      public <T extends RESTResponse> T patch(String path, RESTRequest body, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP PATCH request to the specified path with the provided request body and processes the response with support for response headers.
      Specified by:
      patch in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the PATCH request to.
      body - The REST request to place in the request body.
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      Returns:
      The response entity parsed and converted to its type T.
    • delete

      public <T extends RESTResponse> T delete(String path, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP DELETE request to the specified path without query parameters and processes the response.
      Specified by:
      delete in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the DELETE request to.
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      Returns:
      The response entity parsed and converted to its type T.
    • delete

      public <T extends RESTResponse> T delete(String path, Map<String,String> queryParams, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP DELETE request to the specified path with the provided query parameters and processes the response.
      Specified by:
      delete in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the DELETE request to.
      queryParams - A map of query parameters (key-value pairs) to include in the request (can be null).
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      Returns:
      The response entity parsed and converted to its type T.
    • postForm

      public <T extends RESTResponse> T postForm(String path, Map<String,String> formData, Class<T> responseType, Map<String,String> headers, Consumer<ErrorResponse> errorHandler)
      Sends an HTTP POST request with form data to the specified path and processes the response.
      Specified by:
      postForm in interface RESTClient
      Type Parameters:
      T - The class type of the response for deserialization.
      Parameters:
      path - The URL path to send the POST request to.
      formData - A map of form data (key-value pairs) to include in the request body.
      responseType - The class type of the response for deserialization (Must be registered with the ObjectMapper).
      headers - A map of request headers (key-value pairs) to include in the request (can be null).
      errorHandler - The error handler delegated for HTTP responses, which handles server error responses.
      Returns:
      The response entity parsed and converted to its type T.
    • close

      public void close() throws IOException
      Closes the underlying HTTP client gracefully.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - If an I/O error occurs while closing the HTTP client.
    • builder

      public static HTTPClient.Builder builder(Map<String,String> properties)
      Creates a new instance of the HTTPClient.Builder with the specified properties.
      Parameters:
      properties - A map of properties (key-value pairs) used to configure the HTTP client.
      Returns:
      A new instance of HTTPClient.Builder with the provided properties.