Package com.adyen.httpclient
Class AdyenHttpClient
- java.lang.Object
-
- com.adyen.httpclient.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
CloseableHttpClientinstance 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
Configare applied at two levels:- Connection manager level (
ConnectionConfig):connectTimeoutandsocketTimeoutenforce hard OS-level timeouts on TCP/TLS handshake and socket reads. - Request level (
RequestConfig):responseTimeout,connectionRequestTimeout, anddefaultKeepAliveare set per request.
The shared HTTP client is created from the
Configprovided on the first request. Subsequent changes toConfigtimeout values will not affect the already-created client. Configuration must be finalized before the first API call. *- See Also:
ClientInterface,Config
-
-
Constructor Summary
Constructors Constructor Description AdyenHttpClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the shared HTTP client and releases all pooled connections.ProxygetProxy()Returns the proxy configured for this HTTP client.Stringrequest(String endpoint, String requestBody, Config config)Sends an HTTP POST request to the given endpoint.Stringrequest(String endpoint, String requestBody, Config config, boolean isApiKeyRequired)Sends an HTTP POST request with optional API key authentication.Stringrequest(String endpoint, String requestBody, Config config, boolean isApiKeyRequired, RequestOptions requestOptions)Sends an HTTP POST request with optional API key authentication and request options.Stringrequest(String endpoint, String requestBody, Config config, boolean isApiKeyRequired, RequestOptions requestOptions, ApiConstants.HttpMethod httpMethod)Sends an HTTP request with the specified method, authentication, and request options.Stringrequest(String endpoint, String requestBody, Config config, boolean isApiKeyRequired, RequestOptions requestOptions, ApiConstants.HttpMethod httpMethod, Map<String,String> params)Sends an HTTP request with the specified method, authentication, request options, and query string parameters.voidsetProxy(Proxy proxy)Sets a proxy to use for all HTTP requests made by this client.
-
-
-
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 IOExceptionCloses 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceClientInterface- Specified by:
closein interfaceCloseable- 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:ClientInterfaceSends an HTTP POST request to the given endpoint.- Specified by:
requestin interfaceClientInterface- Parameters:
endpoint- the full URL of the API endpointrequestBody- the JSON request bodyconfig- the client configuration containing authentication and timeout settings- Returns:
- the JSON response body
- Throws:
IOException- if a network error occursHTTPClientException- 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:ClientInterfaceSends an HTTP POST request with optional API key authentication.- Specified by:
requestin interfaceClientInterface- Parameters:
endpoint- the full URL of the API endpointrequestBody- the JSON request bodyconfig- the client configurationisApiKeyRequired- whether API key authentication is mandatory for this request- Returns:
- the JSON response body
- Throws:
IOException- if a network error occursHTTPClientException- 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:ClientInterfaceSends an HTTP POST request with optional API key authentication and request options.- Specified by:
requestin interfaceClientInterface- Parameters:
endpoint- the full URL of the API endpointrequestBody- the JSON request bodyconfig- the client configurationisApiKeyRequired- whether API key authentication is mandatoryrequestOptions- additional request options (idempotency key, custom headers)- Returns:
- the JSON response body
- Throws:
IOException- if a network error occursHTTPClientException- 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:ClientInterfaceSends an HTTP request with the specified method, authentication, and request options.- Specified by:
requestin interfaceClientInterface- Parameters:
endpoint- the full URL of the API endpointrequestBody- the JSON request body (may be null for GET/DELETE)config- the client configurationisApiKeyRequired- whether API key authentication is mandatoryrequestOptions- 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 occursHTTPClientException- 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:ClientInterfaceSends 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:
requestin interfaceClientInterface- Parameters:
endpoint- the full URL of the API endpointrequestBody- the JSON request body (may be null for GET/DELETE)config- the client configurationisApiKeyRequired- whether API key authentication is mandatoryrequestOptions- 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 occursHTTPClientException- if the server returns a non-2xx status code
-
-