Java – SSLHandshakeException: Received fatal alert: handshake_failure

javassl

We are getting this java SSL error while trying to connect server. In running application we are getting this error and then we have to restart the application to make workable again. Can anyone help on this?

at java.lang.Thread.run(Thread.java:662)
Caused by: com.sun.xml.internal.ws.wsdl.parser.InaccessibleWSDLException: 2 counts of InaccessibleWSDLException.
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:161)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:56) 

Best Answer

Picked up from here as i faced similar problem.

The javax.net.ssl.SSLHandshakeException exception is usually thrown when the server you're trying to connect to does not have a valid certificate from an authorized CA.

Put simply, the server you're attempting to connect to is most likely using a self-signed certificate and you have to accomodate for that in your Java code. This involves creating a custom KeyStore, etc.

All i did was provide keystore and keystore password to server(set it in system properties) and the exception disappeared.

javax.net.ssl.keyStore=../keystore/keystoreFile.jks
javax.net.ssl.keyStorePassword=yourPassword
javax.net.ssl.trustStore=../keystore/keystoreFile.jks
javax.net.ssl.trustStorePassword=yourPassword
javax.net.debug=true

you can generate the keystore by using keytool(it is in jdk/bin/keytool)

keytool -genkey -alias myKeyStore -keyalg RSA -keystore /home/aniket/keystore/keystoreFile.jks