0

We have an application where we do some internal http calls to a REST API to fetch the data. But some requests are taking longer than expected so I am trying to increase the timeout duration. I tried below things :

RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(30 * 1000).build(); HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();

But this doesn't solve my issue. This solution works only for the first time. But when I re run this request I get the timeout exception. Can anyone help me with this.

Below is the stack trace

HttpResponseProxy{HTTP/1.1 504 GATEWAY_TIMEOUT [Content-Length: 0, Connection: keep-alive] [Content-Length: 0,Chunked: false]}

Rakesh Gourineni
  • 1,361
  • 5
  • 16
  • 30

1 Answers1

0

You should also set socketTimeout (with setSocketTimeout() method).

  • I tried this too. But it didn't work. Your help is greatly apreciated :) – Rakesh Gourineni May 30 '17 at 23:56
  • Could you add here full stack trace of your exception? – Alexander Kirakozov May 31 '17 at 08:42
  • I added stacktrace to my question. Thanks for your help in advance – Rakesh Gourineni May 31 '17 at 13:25
  • 504 GATEWAY_TIMEOUT is timeout on server. Is it your REST API service or external? Could you look deeply on server logs and identify the reason of timeout from the server side? – Alexander Kirakozov May 31 '17 at 15:15
  • I also see, that by default RequestConfig timeouts are set to -1, it's mean infinite timeout. So, I think that it's not problem in your client `this.connectionRequestTimeout = -1; this.connectTimeout = -1;this.socketTimeout = -1;` – Alexander Kirakozov May 31 '17 at 15:19
  • I was wrong about -1 value: "A timeout value of zero is interpreted as an infinite timeout. A negative value is interpreted as undefined (system default)." If system default is not defined, timeout would be infinite. I suggest try to make http request with some console utilits (like [curl](https://curl.haxx.se/docs/httpscripting.html)) to clearly identify, that server returns 504 not only for your client. – Alexander Kirakozov May 31 '17 at 21:14
  • Thanks for taking time Alexander. I will try curl request and will let you know. Actually I used postman to run the requests. Do you think using curl result might be different? Once again appreciate your time. – Rakesh Gourineni Jun 01 '17 at 00:41
  • I tried the curl Request. I dont see any response on my terminal. Can you please help me. – Rakesh Gourineni Jun 05 '17 at 14:35
  • Try `curl -v` for diagnostic. Could you write full curl request and result here? – Alexander Kirakozov Jun 08 '17 at 15:44
  • curl -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"BusinessStatus": ["HEADQUARTER", "SINGLE LOC"], "ResourceType": "Core", "LocationSalesVolumeRange": ["1-500000"], "LocationEmployeesSizeRange": ["1-4"], "RequestType": "Company", "Limit": 2000, "Offset": 92000, "PrimarySicList": ["811103"]}' http://localhost:8090/companies/search This is the request. I dont see any response. – Rakesh Gourineni Jun 08 '17 at 17:43
  • Add `-v` flag to look at full response from your server (there should be response headers, http status code and etc). May be your server return empty response for this request. Could you copy here result of request with `-v` flag? – Alexander Kirakozov Jun 09 '17 at 07:47
  • Alexander, Below is the response from curl if I add the -v tag ------------- curl 7.51.0 (x86_64-apple-darwin16.0) libcurl/7.51.0 SecureTransport zlib/1.2.8 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features: AsynchDNS IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets – Rakesh Gourineni Jun 09 '17 at 14:48