Class FileClient
java.lang.Object
com.digicert.validation.client.file.FileClient
- All Implemented Interfaces:
Closeable
,AutoCloseable
Client for handling file validation requests.
This client is configured with custom settings and a custom redirect strategy.
It uses Apache HttpClient for making HTTP requests.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final DcvContext
The context where we can find the needed dependencies and configuration.private org.apache.hc.client5.http.impl.classic.CloseableHttpClient
The HTTP client used to make requests.private final int
The maximum length of the response body to read.private final String
The user agent to include in the request headers. -
Constructor Summary
ConstructorsConstructorDescriptionFileClient
(DcvContext dcvContext) Constructs a new FileClient with the specified configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the HTTP client and releases any system resources associated with it.(package private) org.apache.hc.client5.http.impl.classic.CloseableHttpClient
Creates an HTTP client with the specified configuration.executeRequest
(String fileUrl) Executes an HTTP GET request to the specified file URL.private org.apache.hc.client5.http.config.ConnectionConfig
Creates a ConnectionConfig based on the specified configuration.(package private) CustomDnsResolver
Creates a CustomDnsResolver based on the specified configuration.private org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager
Creates a PoolingHttpClientConnectionManager based on the specified configuration.private org.apache.hc.client5.http.config.RequestConfig
Creates a RequestConfig based on the specified configuration.private org.apache.hc.core5.http.io.SocketConfig
Creates a SocketConfig based on the specified configuration.private SSLContext
Creates an SSLContext based on the specified configuration.
-
Field Details
-
httpClient
private org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClientThe HTTP client used to make requests. -
userAgent
The user agent to include in the request headers.The `userAgent` string is included in the headers of each HTTP request made by this client. It identifies the client software to the server.
-
maxBodyLength
private final int maxBodyLengthThe maximum length of the response body to read.The `maxBodyLength` is the maximum number of bytes to read from the response body. If the response body is larger than this value, it is truncated.
-
dcvContext
The context where we can find the needed dependencies and configuration.We are storing the context here, which allows for lazy initialization of the HTTP client.
-
-
Constructor Details
-
FileClient
Constructs a new FileClient with the specified configuration.- Parameters:
dcvContext
- context where we can find the needed dependencies and configuration
-
-
Method Details
-
executeRequest
Executes an HTTP GET request to the specified file URL.If an exception occurs during the request or response processing, it is logged, and the appropriate error information is set in the `FileClientResponse`.
- Parameters:
fileUrl
- The URL of the file to request.- Returns:
- A FileClientResponse containing either the response data or an exception if the request failed.
-
createHttpClient
org.apache.hc.client5.http.impl.classic.CloseableHttpClient createHttpClient()Creates an HTTP client with the specified configuration.The HTTP client is created with a custom redirect strategy, a custom DNS resolver, and a custom SSL context.
- Returns:
- A CloseableHttpClient instance.
-
getRequestConfig
private org.apache.hc.client5.http.config.RequestConfig getRequestConfig()Creates a RequestConfig based on the specified configuration.- Returns:
- A RequestConfig instance.
-
getPoolingHttpClientConnectionManager
private org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager getPoolingHttpClientConnectionManager()Creates a PoolingHttpClientConnectionManager based on the specified configuration.- Returns:
- A PoolingHttpClientConnectionManager instance.
-
getSocketConfig
private org.apache.hc.core5.http.io.SocketConfig getSocketConfig()Creates a SocketConfig based on the specified configuration.- Returns:
- A SocketConfig instance.
-
getConnectionConfig
private org.apache.hc.client5.http.config.ConnectionConfig getConnectionConfig()Creates a ConnectionConfig based on the specified configuration.- Returns:
- A ConnectionConfig instance.
-
getSslContext
Creates an SSLContext based on the specified configuration.- Returns:
- An SSLContext instance.
-
getCustomDnsResolver
CustomDnsResolver getCustomDnsResolver()Creates a CustomDnsResolver based on the specified configuration. This method is package-private for testing purposes.- Returns:
- A CustomDnsResolver instance.
-
close
Closes the HTTP client and releases any system resources associated with it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- If an I/O error occurs.
-