Class HttpSupport
This class centralizes common HTTP-related functionality required by the AI provider integrations, including:
- creation of a configured
HttpClient - provision of a shared Jackson
ObjectMapper - execution of JSON-oriented HTTP requests
- construction of JSON
POSTrequests
The helper is intentionally lightweight and provider-agnostic. It does not implement provider-specific authentication, endpoint selection, or response normalization logic; those responsibilities remain in the concrete provider clients.
The internally managed ObjectMapper is configured to ignore unknown
JSON properties so that provider response deserialization remains resilient
to non-breaking API changes.
Instances of this class are immutable after construction.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHttpSupport(Duration timeout) Creates a new HTTP support helper with the specified connection timeout. -
Method Summary
Modifier and TypeMethodDescriptionReturns the configured HTTP client used by this helper.Creates a JSON-oriented HTTPPOSTrequest builder.com.fasterxml.jackson.databind.ObjectMapperReturns the configured Jackson object mapper used for JSON serialization and deserialization.postJson(HttpRequest request) Executes an HTTP request expected to return a JSON response body and returns the response content as text.
-
Constructor Details
-
HttpSupport
Creates a new HTTP support helper with the specified connection timeout.The supplied timeout is used as the connection timeout of the underlying
HttpClient. Request-specific timeouts may still be configured independently on individualHttpRequestinstances.The constructor also initializes a Jackson
ObjectMapperconfigured withDeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIESdisabled.- Parameters:
timeout- connection timeout used for the underlying HTTP client
-
-
Method Details
-
httpClient
Returns the configured HTTP client used by this helper.- Returns:
- configured HTTP client instance
-
objectMapper
public com.fasterxml.jackson.databind.ObjectMapper objectMapper()Returns the configured Jackson object mapper used for JSON serialization and deserialization.- Returns:
- configured object mapper instance
-
postJson
Executes an HTTP request expected to return a JSON response body and returns the response content as text.The method sends the supplied request using the internally configured
HttpClient. Responses with HTTP status codes outside the successful2xxrange are treated as failures and cause anIOExceptionto be thrown containing both the status code and response body.Despite the method name, the request itself is not required to be a
POSTrequest; the method simply executes the provided request and validates that the response indicates success.- Parameters:
request- HTTP request to execute- Returns:
- response body as text
- Throws:
IOException- if request execution fails or if the HTTP response status code is outside the successful2xxrangeInterruptedException- if the calling thread is interrupted while waiting for the response
-
jsonPost
Creates a JSON-oriented HTTPPOSTrequest builder.The returned builder is preconfigured with:
- the supplied target
URI - the supplied request timeout
Content-Type: application/json- a
POSTrequest body containing the supplied JSON text
Callers may further customize the returned builder, for example by adding authentication or provider-specific headers, before invoking
HttpRequest.Builder.build().- Parameters:
uri- target URI of the requestbody- serialized JSON request bodytimeout- request timeout- Returns:
- preconfigured HTTP request builder for a JSON
POSTrequest
- the supplied target
-