Created
July 6, 2017 02:25
-
-
Save marciorodrigues87/0732d12f5ea029396fb47197c3aea6a9 to your computer and use it in GitHub Desktop.
RestTemplateConfigStepSeven.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final RequestConfig requestConfig = RequestConfig.custom() | |
.setConnectionRequestTimeout(100) | |
.setConnectTimeout(500) | |
.setSocketTimeout(1000) | |
.build(); | |
final HttpClient httpClient = HttpClients.custom() | |
.setMaxConnPerRoute(100) | |
.setMaxConnTotal(1000) | |
.setConnectionTimeToLive(30, MINUTES) | |
.setRetryHandler((IOException exception, int executionCount, HttpContext context) -> { | |
return executionCount <= 3; | |
}) | |
.setServiceUnavailableRetryStrategy(new DefaultServiceUnavailableRetryStrategy(3, 1)) | |
.setDefaultRequestConfig(requestConfig) | |
.build(); | |
final RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient)); | |
restTemplate.setInterceptors(asList(new BasicAuthorizationInterceptor("user", "password"))); // <-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment