Class RestTemplateHelper

java.lang.Object
fr.becpg.repo.helper.RestTemplateHelper

public final class RestTemplateHelper extends Object
Helper class for RestTemplate configuration with optimized connection pooling, DNS cache management, and DNS resolution logging.
Author:
matthieu
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
    Custom request factory that logs DNS resolution and adds standard headers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final org.apache.hc.core5.util.Timeout
     
    private static final int
     
    private static final org.apache.hc.core5.util.Timeout
     
    private static final org.springframework.web.client.RestTemplate
     
    private static final org.slf4j.Logger
     
    private static final org.apache.hc.core5.util.Timeout
     
    private static final org.springframework.web.client.RestTemplate
     
    private static final int
     
    private static final int
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static org.apache.hc.client5.http.config.ConnectionConfig
    buildConnectionConfig(org.apache.hc.core5.util.Timeout socketTimeout)
    Builds connection configuration with specified timeouts.
    static String[]
    Performs manual DNS resolution check for a hostname.
    private static org.apache.hc.client5.http.impl.classic.CloseableHttpClient
    createHttpClient(org.apache.hc.core5.util.Timeout socketTimeout)
    Creates a configured HTTP client with connection pooling and timeout settings.
    private static org.springframework.web.client.RestTemplate
    createRestTemplate(org.apache.hc.core5.util.Timeout socketTimeout)
    Creates a configured RestTemplate with the specified socket timeout.
    static org.springframework.web.client.RestTemplate
    Gets the default RestTemplate instance with standard timeout settings.
    static org.springframework.web.client.RestTemplate
    Gets the RestTemplate instance with extended timeout settings for long-running operations.

    Methods inherited from class java.lang.Object

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

    • logger

      private static final org.slf4j.Logger logger
    • MAX_TOTAL_CONNECTIONS

      private static final int MAX_TOTAL_CONNECTIONS
      See Also:
    • MAX_CONNECTIONS_PER_ROUTE

      private static final int MAX_CONNECTIONS_PER_ROUTE
      See Also:
    • CONNECTION_TTL_SECONDS

      private static final int CONNECTION_TTL_SECONDS
      See Also:
    • CONNECTION_TIMEOUT

      private static final org.apache.hc.core5.util.Timeout CONNECTION_TIMEOUT
    • DEFAULT_SOCKET_TIMEOUT

      private static final org.apache.hc.core5.util.Timeout DEFAULT_SOCKET_TIMEOUT
    • LONG_SOCKET_TIMEOUT

      private static final org.apache.hc.core5.util.Timeout LONG_SOCKET_TIMEOUT
    • defaultRestTemplate

      private static final org.springframework.web.client.RestTemplate defaultRestTemplate
    • longTimeoutRestTemplate

      private static final org.springframework.web.client.RestTemplate longTimeoutRestTemplate
  • Constructor Details

    • RestTemplateHelper

      private RestTemplateHelper()
  • Method Details

    • getRestTemplate

      public static org.springframework.web.client.RestTemplate getRestTemplate()
      Gets the default RestTemplate instance with standard timeout settings.
      Returns:
      configured RestTemplate instance
    • getRestTemplateLongTimeout

      public static org.springframework.web.client.RestTemplate getRestTemplateLongTimeout()
      Gets the RestTemplate instance with extended timeout settings for long-running operations.
      Returns:
      configured RestTemplate instance with long timeout
    • createRestTemplate

      private static org.springframework.web.client.RestTemplate createRestTemplate(org.apache.hc.core5.util.Timeout socketTimeout)
      Creates a configured RestTemplate with the specified socket timeout.
      Parameters:
      socketTimeout - the socket timeout to apply
      Returns:
      configured RestTemplate instance
    • createHttpClient

      private static org.apache.hc.client5.http.impl.classic.CloseableHttpClient createHttpClient(org.apache.hc.core5.util.Timeout socketTimeout)
      Creates a configured HTTP client with connection pooling and timeout settings.
      Parameters:
      socketTimeout - the socket timeout to apply
      Returns:
      configured CloseableHttpClient
    • buildConnectionConfig

      private static org.apache.hc.client5.http.config.ConnectionConfig buildConnectionConfig(org.apache.hc.core5.util.Timeout socketTimeout)
      Builds connection configuration with specified timeouts.
      Parameters:
      socketTimeout - the socket timeout to apply
      Returns:
      configured ConnectionConfig
    • checkDnsResolution

      public static String[] checkDnsResolution(String hostname)
      Performs manual DNS resolution check for a hostname.
      Parameters:
      hostname - the hostname to resolve
      Returns:
      array of resolved IP addresses, or empty array if resolution fails