1

I am trying to do a get request on an URL. When I hit the URL in a web browser it normally takes around 2 mins to load.

When I am trying to call it from Java - I get a SocketException connection reset error.

Error: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210)
    at java.net.SocketInputStream.read(SocketInputStream.java:141)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
    at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:940)
    at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:735)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:678)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:706)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1569)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)

I am trying to do a getResponseCode, I am getting the same error when I am trying to read from the stream as well.

How do I resolve this?

I tried setting the connection timeout and read timeout to 5 mins. None of them worked.

Edit: [Adding code] The following is the code, I am getting the same error while doing a getResponseCode and reading the stream using getInputStream.

        HttpURLConnection connection = (HttpURLConnection) urlObj.openConnection();
        connection.setRequestMethod("GET");
        connection.setConnectTimeout(TIMEOUT); //5 mins
        connection.setReadTimeout(TIMEOUT); //5 mins
        connection.getResponseCode();
        IOUtils.toString(connection.getInputStream(), StandardCharsets.UTF_8);

I don't think this is a server issue because I am able to do a get with other params which would usually load in 15-30 secs in the browser. Only this particular request is failing. (this request takes 2 mins to load in the browser)

Rakesh D
  • 11
  • 3
  • Can you post the code snippet you are using for this ? – Ramachandran.A.G Nov 05 '17 at 02:06
  • It's most likely a problem with the server. If so, you can't do anything but retry the request. – erickson Nov 05 '17 at 02:12
  • To add more details, 1) I am getting the socket connection reset exception roughly after 140secs. 2) I also see that the get request is being called twice. [On the server side I see two entries of the same request] 3) When reducing the read timeout to 1 min - I get a SocketTimeoutException: Read timed out error (expected) I am wondering if there is a max time limit for reads? Also when the server isn't responsive will httpurlconnection send a second request? HttpUrlConnection is poorly documented. It doesn't give many details. – Rakesh D Nov 05 '17 at 20:03
  • What is the TLS/SSL version that the server supports? – QuakeCore Nov 05 '17 at 20:23
  • TLSv1/SSLv3 is what is being displayed when I do an "openssl s_client -connect my.website.com:443" – Rakesh D Nov 05 '17 at 21:07

0 Answers0