Class AdyenHttpClient

  • All Implemented Interfaces:
    ClientInterface, Closeable, AutoCloseable

    public class AdyenHttpClient
    extends Object
    implements ClientInterface
    HTTP client implementation to invoke the Adyen APIs.

    This client maintains a shared CloseableHttpClient instance that is lazily initialized on the first request and reused for all subsequent requests. This enables connection pooling, TCP and TLS session reuse, and natural backpressure under high concurrency.

    Timeout values from Config are applied at two levels:

    • Connection manager level (ConnectionConfig): connectTimeout and socketTimeout enforce hard OS-level timeouts on TCP/TLS handshake and socket reads.
    • Request level (RequestConfig): responseTimeout, connectionRequestTimeout, and defaultKeepAlive are set per request.

    The shared HTTP client is created from the Config provided on the first request. Subsequent changes to Config timeout values will not affect the already-created client. Configuration must be finalized before the first API call. *

    See Also:
    ClientInterface, Config
    • Constructor Detail

      • AdyenHttpClient

        public AdyenHttpClient()
    • Method Detail

      • getProxy

        public Proxy getProxy()
        Returns the proxy configured for this HTTP client.
        Returns:
        the proxy, or null if no proxy is set
      • setProxy

        public void setProxy​(Proxy proxy)
        Sets a proxy to use for all HTTP requests made by this client.
        Parameters:
        proxy - the proxy (e.g. new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", port)))
      • close

        public void close()
                   throws IOException
        Closes the shared HTTP client and releases all pooled connections. This method is idempotent and thread-safe; calling it multiple times has no additional effect.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface ClientInterface
        Specified by:
        close in interface Closeable
        Throws:
        IOException - if an I/O error occurs while closing the underlying client
      • request

        public String request​(String endpoint,
                              String requestBody,
                              Config config)
                       throws IOException,
                              HTTPClientException
        Description copied from interface: ClientInterface
        Sends an HTTP POST request to the given endpoint.
        Specified by:
        request in interface ClientInterface
        Parameters:
        endpoint - the full URL of the API endpoint
        requestBody - the JSON request body
        config - the client configuration containing authentication and timeout settings
        Returns:
        the JSON response body
        Throws:
        IOException - if a network error occurs
        HTTPClientException - if the server returns a non-2xx status code
      • request

        public String request​(String endpoint,
                              String requestBody,
                              Config config,
                              boolean isApiKeyRequired)
                       throws IOException,
                              HTTPClientException
        Description copied from interface: ClientInterface
        Sends an HTTP POST request with optional API key authentication.
        Specified by:
        request in interface ClientInterface
        Parameters:
        endpoint - the full URL of the API endpoint
        requestBody - the JSON request body
        config - the client configuration
        isApiKeyRequired - whether API key authentication is mandatory for this request
        Returns:
        the JSON response body
        Throws:
        IOException - if a network error occurs
        HTTPClientException - if the server returns a non-2xx status code
      • request

        public String request​(String endpoint,
                              String requestBody,
                              Config config,
                              boolean isApiKeyRequired,
                              RequestOptions requestOptions)
                       throws IOException,
                              HTTPClientException
        Description copied from interface: ClientInterface
        Sends an HTTP POST request with optional API key authentication and request options.
        Specified by:
        request in interface ClientInterface
        Parameters:
        endpoint - the full URL of the API endpoint
        requestBody - the JSON request body
        config - the client configuration
        isApiKeyRequired - whether API key authentication is mandatory
        requestOptions - additional request options (idempotency key, custom headers)
        Returns:
        the JSON response body
        Throws:
        IOException - if a network error occurs
        HTTPClientException - if the server returns a non-2xx status code
      • request

        public String request​(String endpoint,
                              String requestBody,
                              Config config,
                              boolean isApiKeyRequired,
                              RequestOptions requestOptions,
                              ApiConstants.HttpMethod httpMethod)
                       throws IOException,
                              HTTPClientException
        Description copied from interface: ClientInterface
        Sends an HTTP request with the specified method, authentication, and request options.
        Specified by:
        request in interface ClientInterface
        Parameters:
        endpoint - the full URL of the API endpoint
        requestBody - the JSON request body (may be null for GET/DELETE)
        config - the client configuration
        isApiKeyRequired - whether API key authentication is mandatory
        requestOptions - additional request options (idempotency key, custom headers)
        httpMethod - the HTTP method (GET, POST, PATCH, DELETE)
        Returns:
        the JSON response body
        Throws:
        IOException - if a network error occurs
        HTTPClientException - if the server returns a non-2xx status code
      • request

        public String request​(String endpoint,
                              String requestBody,
                              Config config,
                              boolean isApiKeyRequired,
                              RequestOptions requestOptions,
                              ApiConstants.HttpMethod httpMethod,
                              Map<String,​String> params)
                       throws IOException,
                              HTTPClientException
        Description copied from interface: ClientInterface
        Sends an HTTP request with the specified method, authentication, request options, and query string parameters. This is the most complete overload used by all API service classes.
        Specified by:
        request in interface ClientInterface
        Parameters:
        endpoint - the full URL of the API endpoint
        requestBody - the JSON request body (may be null for GET/DELETE)
        config - the client configuration
        isApiKeyRequired - whether API key authentication is mandatory
        requestOptions - additional request options (idempotency key, custom headers)
        httpMethod - the HTTP method (GET, POST, PATCH, DELETE)
        params - query string parameters appended to the URL
        Returns:
        the JSON response body
        Throws:
        IOException - if a network error occurs
        HTTPClientException - if the server returns a non-2xx status code