title: How to add a fix to avoid 504 Gateway timeout error
body: <p>I am getting 504 Gateway timeout error from my GET method call to another service.
  Recently I added a fix by increasing the timeout period but that didn't help.</p>
  
  <p>This is what I have tried</p>
  
  <pre><code>   public void getUserInformation(final Integer userId) {
          HttpClient httpClient = getBasicAuthDefaultHttpClient();
          HttpGet httpGet = new HttpGet("http://xxxx/users/"+userId);
          httpGet.addHeader("userid", userid);
          httpGet.addHeader("secret", secret);
          try {
              HttpResponse response = httpClient.execute(httpGet);
              HttpEntity entity = response.getEntity();
  
              if (entity != null &amp;&amp; HttpStatus.OK.value() == 
                 response.getStatusLine().getStatusCode()) {
                 ObjectMapper objectMapper = new ObjectMapper();
                 userInfo = objectMapper.readValue(entity.getContent(), 
                 UserInfo.class);
              } else {
                  logger.error("Call to the service failed: response code: 
                  {}", response.getStatusLine().getStatusCode());
              }
          } catch (Exception e) {
              logger.error("Exception: "+ e);
          }
  
     }
  
    public HttpClient getBasicAuthDefaultHttpClient() {
      CredentialsProvider provider = new BasicCredentialsProvider();
      UsernamePasswordCredentials creds = new 
      UsernamePasswordCredentials(user, password);
      provider.setCredentials(AuthScope.ANY, creds);
  
      //Fix to avoid HTTP 504 ERROR (GATEWAY TIME OUT ERROR) for ECM calls
      RequestConfig.Builder requestBuilder = RequestConfig.custom();
      requestBuilder.setConnectTimeout(30 * 1000);
      requestBuilder.setConnectionRequestTimeout(30 * 1000);
  
      HttpClientBuilder builder = HttpClientBuilder.create();
      builder.setDefaultRequestConfig(requestBuilder.build());
      builder.setDefaultCredentialsProvider(provider).build();
  
      return builder.build();
    }
  </code></pre>
  
  <p>I am calling this process within a loop to process records, this works for most of the records but fails for few userId's in that.
  But what I noticed is everything will work fine when I run only the failed records, not sure whats the problem in this case.</p>
  
  <p>I thought of calling the method again when I receive 504 to invoke it again hoping to receive 200 next time.</p>
  
  <p>Not sure is this the good idea. Any advice would be greatly appreciated.</p>