Friday 20 September 2019

RestTemplate: Configure Request Time out


private static final RestTemplate REST_TEMPLATE = new RestTemplate(getClientHttpRequestFactory());

private static ClientHttpRequestFactory getClientHttpRequestFactory() {
    int timeout = 5000;
    RequestConfig config = RequestConfig.custom()
      .setConnectTimeout(timeout)
      .setConnectionRequestTimeout(timeout)
      .setSocketTimeout(timeout)
      .build();
    CloseableHttpClient client = HttpClientBuilder
      .create()
      .setDefaultRequestConfig(config)
      .build();
    return new HttpComponentsClientHttpRequestFactory(client);
}
You can get complete working application from this link.

Previous                                                    Next                                                    Home

No comments:

Post a Comment