Class FileClient

java.lang.Object
com.digicert.validation.client.file.FileClient
All Implemented Interfaces:
Closeable, AutoCloseable

public class FileClient extends Object implements Closeable
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

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    FileClient(DcvContext dcvContext)
    Constructs a new FileClient with the specified configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • httpClient

      private org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient
      The HTTP client used to make requests.
    • userAgent

      private final String 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 maxBodyLength
      The 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

      private final DcvContext 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

      public FileClient(DcvContext dcvContext)
      Constructs a new FileClient with the specified configuration.
      Parameters:
      dcvContext - context where we can find the needed dependencies and configuration
  • Method Details

    • executeRequest

      public FileClientResponse executeRequest(String fileUrl)
      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

      private SSLContext 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

      public void close() throws IOException
      Closes the HTTP client and releases any system resources associated with it.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - If an I/O error occurs.