Advertisement
Guest User

Untitled

a guest
May 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. HttpClient httpClient = org.apache.http.impl.client.HttpClientBuilder.create().build();
  2.  
  3. HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
  4. factory.setConnectTimeout((int) TimeUnit.MINUTES.toMillis(2));
  5. factory.setReadTimeout((int) TimeUnit.MINUTES.toMillis(2));
  6. factory.setHttpClient(httpClient);
  7.  
  8. RestTemplate restTemplate = new RestTemplate(factory);
  9.  
  10. int tries, maxRetries = 5;
  11. Connection connection;
  12. do {
  13. try {
  14. // initialize connection
  15. } catch (SocketTimeoutException ex) {
  16. ++tries;
  17. if (maxRetries < tries) {
  18. // exit
  19. }
  20. // sleep for some time between attempts
  21. }
  22. } while (connection == null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement