Class HttpSupport

java.lang.Object
org.egothor.methodatlas.ai.HttpSupport

public final class HttpSupport extends Object
Small HTTP utility component used by AI provider clients for outbound network communication and JSON processing support.

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 POST requests

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 Details

    • HttpSupport

      public HttpSupport(Duration timeout)
      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 individual HttpRequest instances.

      The constructor also initializes a Jackson ObjectMapper configured with DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES disabled.

      Parameters:
      timeout - connection timeout used for the underlying HTTP client
  • Method Details

    • httpClient

      public HttpClient 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

      public String postJson(HttpRequest request) throws IOException, InterruptedException
      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 successful 2xx range are treated as failures and cause an IOException to be thrown containing both the status code and response body.

      Despite the method name, the request itself is not required to be a POST request; 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 successful 2xx range
      InterruptedException - if the calling thread is interrupted while waiting for the response
    • jsonPost

      public HttpRequest.Builder jsonPost(URI uri, String body, Duration timeout)
      Creates a JSON-oriented HTTP POST request builder.

      The returned builder is preconfigured with:

      • the supplied target URI
      • the supplied request timeout
      • Content-Type: application/json
      • a POST request 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 request
      body - serialized JSON request body
      timeout - request timeout
      Returns:
      preconfigured HTTP request builder for a JSON POST request