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.TimeoutConstantCONNECTION_TIMEOUTprivate static final intConstantCONNECTION_TTL_SECONDS=5private static final org.apache.hc.core5.util.TimeoutConstantDEFAULT_SOCKET_TIMEOUTprivate static final org.springframework.web.client.RestTemplateConstantdefaultRestTemplateprivate static final org.slf4j.LoggerConstantloggerprivate static final org.apache.hc.core5.util.TimeoutConstantLONG_SOCKET_TIMEOUTprivate static final org.springframework.web.client.RestTemplateConstantlongTimeoutRestTemplateprivate static final intConstantMAX_CONNECTIONS_PER_ROUTE=20private static final intConstantMAX_TOTAL_CONNECTIONS=50 -
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 loggerConstantlogger -
MAX_TOTAL_CONNECTIONS
private static final int MAX_TOTAL_CONNECTIONSConstantMAX_TOTAL_CONNECTIONS=50- See Also:
-
MAX_CONNECTIONS_PER_ROUTE
private static final int MAX_CONNECTIONS_PER_ROUTEConstantMAX_CONNECTIONS_PER_ROUTE=20- See Also:
-
CONNECTION_TTL_SECONDS
private static final int CONNECTION_TTL_SECONDSConstantCONNECTION_TTL_SECONDS=5- See Also:
-
CONNECTION_TIMEOUT
private static final org.apache.hc.core5.util.Timeout CONNECTION_TIMEOUTConstantCONNECTION_TIMEOUT -
DEFAULT_SOCKET_TIMEOUT
private static final org.apache.hc.core5.util.Timeout DEFAULT_SOCKET_TIMEOUTConstantDEFAULT_SOCKET_TIMEOUT -
LONG_SOCKET_TIMEOUT
private static final org.apache.hc.core5.util.Timeout LONG_SOCKET_TIMEOUTConstantLONG_SOCKET_TIMEOUT -
defaultRestTemplate
private static final org.springframework.web.client.RestTemplate defaultRestTemplateConstantdefaultRestTemplate -
longTimeoutRestTemplate
private static final org.springframework.web.client.RestTemplate longTimeoutRestTemplateConstantlongTimeoutRestTemplate
-
-
Constructor Details
-
RestTemplateHelper
private RestTemplateHelper()Constructor for 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
-