Package fr.becpg.repo.helper
Class RestTemplateHelper
java.lang.Object
fr.becpg.repo.helper.RestTemplateHelper
Helper class for RestTemplate configuration with optimized connection pooling,
DNS cache management, and DNS resolution logging.
- Author:
- matthieu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classCustom request factory that logs DNS resolution and adds standard headers. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.apache.hc.core5.util.Timeoutprivate static final intprivate static final org.apache.hc.core5.util.Timeoutprivate static final org.springframework.web.client.RestTemplateprivate static final org.slf4j.Loggerprivate static final org.apache.hc.core5.util.Timeoutprivate static final org.springframework.web.client.RestTemplateprivate static final intprivate static final int -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static org.apache.hc.client5.http.config.ConnectionConfigbuildConnectionConfig(org.apache.hc.core5.util.Timeout socketTimeout) Builds connection configuration with specified timeouts.static String[]checkDnsResolution(String hostname) Performs manual DNS resolution check for a hostname.private static org.apache.hc.client5.http.impl.classic.CloseableHttpClientcreateHttpClient(org.apache.hc.core5.util.Timeout socketTimeout) Creates a configured HTTP client with connection pooling and timeout settings.private static org.springframework.web.client.RestTemplatecreateRestTemplate(org.apache.hc.core5.util.Timeout socketTimeout) Creates a configured RestTemplate with the specified socket timeout.static org.springframework.web.client.RestTemplateGets the default RestTemplate instance with standard timeout settings.static org.springframework.web.client.RestTemplateGets the RestTemplate instance with extended timeout settings for long-running operations.
-
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
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
-