2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

Received fatal alert: handshake_failure, exception is javax.net.ssl.SSLHandshakeException

I am consuming some web serices by using postman or restclient from brower and its works perfectly as per the expectation. But when the same I implemented through Spring resttemplate getting the below exception.


Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

    at sun.security.ssl.Alerts.getSSLException(Unknown Source)

    at sun.security.ssl.Alerts.getSSLException(Unknown Source)

    at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)

    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)

    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)

    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)

    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)


And I am damned sure that, the issue is not because of Spring and it may because of JDK what I installed on my machine. Can anybody let me know the solution please?

JDK Version : jdk1.7.0_79

userimage

Yes you are correct its not because of spring resttemplate and its due to the URL which might be using TLS 1.2 which is by default disabled from JDK 1.6 or 1.7 and its enabled in JDK 1.8 . So if you use JDK 1.8 then this issue will not come. Better to use the below piece of line on your code before make any Web service call.


System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2");

Answer is