Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Failing to make HTTPS calls intermittently

1051264Oct 29 2013 — edited Nov 2 2013

Hello everyone,

I am intermittently getting issues when connecting to a HTTPS url. I don't think its a certificate issue, as the same code works some time and fails other time.

Exception details.

Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
  at com
.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:882)
  at com
.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1188)
  at com
.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1215)
  at com
.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1199)
  at sun
.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:434)
  at sun
.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:166)
  at sun
.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:133)
  
... 35 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
  at com
.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:462)
  at com
.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:863)
  
... 41 more



The similar issue was reported on many other sites, but did not find any good answer behind root cause and about the solution.



Here's what my code does. I tried running this chunk of code in separate threads as well and noticed that some threads did pass successfully, while some failed with above exception in same program execution flow.

Does it anything to have with server URL that I am hitting. When I accessed the URL from browser, I noticed that server certificate is using TLS 1.0

            java.net.URL url = new java.net.URL(URL);

            connection = url.openConnection();

            connection.setDoOutput(true);

            oStream = connection.getOutputStream();

            out = new OutputStreamWriter(oStream);

            out.write("xml=" + data);

            // close to flush and release writer

            out.close();

            out = null;

            iStream = connection.getInputStream();

            isReader = new InputStreamReader(iStream);

            response = new BufferedReader(isReader);

            StringBuffer returnData = new StringBuffer();

            returnData.setLength(0);

            String line = null;

            // readLine() throws an I/O error

            while ((line = response.readLine()) != null) {

                returnData.append(line);

            }

Here are the environment details

OS: Linux

Jdk: build 1.6.0_29-b11 (I also tried with build 1.6.0_37-b06)

Is this a bug in JDK security implementation?

How shall I go about fixing or rather first determining the root cause of issue?

Any help is very much appreciated.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 30 2013
Added on Oct 29 2013
3 comments
14,618 views