Package org.apache.gravitino.client
Class HTTPClient
java.lang.Object
org.apache.gravitino.client.HTTPClient
- All Implemented Interfaces:
Closeable
,AutoCloseable
,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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Builder class for configuring and creating instances of HTTPClient. -
Method Summary
Modifier and TypeMethodDescriptionstatic HTTPClient.Builder
Creates a new instance of the HTTPClient.Builder with the specified properties.void
close()
Closes the underlying HTTP client gracefully.<T extends RESTResponse>
Tdelete
(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.<T extends RESTResponse>
Tdelete
(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.<T extends RESTResponse>
Tget
(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.void
Sends an HTTP HEAD request to the specified path and processes the response.<T extends RESTResponse>
Tpatch
(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.<T extends RESTResponse>
Tpost
(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.<T extends RESTResponse>
Tpost
(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.<T extends RESTResponse>
TpostForm
(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.<T extends RESTResponse>
Tput
(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.<T extends RESTResponse>
Tput
(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.
-
Method Details
-
head
Sends an HTTP HEAD request to the specified path and processes the response.- Specified by:
head
in interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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 interfaceRESTClient
- 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
Closes the underlying HTTP client gracefully.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an I/O error occurs while closing the HTTP client.
-
builder
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.
-