0

I am trying to communicating with another https URL by using "HttpClient API" method. But I am getting the below exception:

SSLHandshakeException: Received fatal alert: handshake_failure

JDK 1.7

Server: Wildfly 9

I have imported the certificate into the key store as well

Java code

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.MultipartPostMethod;
import org.apache.commons.httpclient.protocol.Protocol;

class SSLTest {
    public static void main(String args[]) {    
        String responseString = ""; 
        String sslStr = "https";
        String urlString ="https://<urlString>/Registration?Param1=test";
        HttpClient client = new HttpClient();
        if(sslStr.equals("https")){
           try{
            Protocol httpsProtocol = new Protocol( "https", new EasySSLProtocolSocketFactory(), serverPort);
            Protocol.registerProtocol("https", httpsProtocol);
            client.getHostConfiguration().setHost(serverip, serverPort,httpsProtocol);
           }catch(Exception e2){
               System.out.println("Fail to create certificate :"+e2.getMessage());
           }
        }
        MultipartPostMethod mPost = new MultipartPostMethod(urlString);
        client.setConnectionTimeout(1000*3*60);

        try{
        int statusCode = client.executeMethod(mPost);
        }catch(Exception e2){
            System.out.println("Exception: "+e2.getMessage());
        }
        responseString = mPost.getResponseBodyAsString();
        mPost.releaseConnection();

        System.out.println("responseString = " + responseString);
    }
}   

-------
Output
-------

Exception: Received fatal alert: handshake_failure

responseString = NULL

Expected output: It should reach the specified URL Server. But here, unable to communicate with the server.

Thanks in advance.

  • First verify that your server is up, verify that it's accessible on HTTPS (port 443). If everything is good, the handshake must be done at least. – Rafik Apr 24 '19 at 16:23
  • Rafik, The URL is accessible and telnet is also happening. – mathiyarasu.T Arasu Apr 24 '19 at 16:45
  • Not much information to go on, could be a duplicate of https://stackoverflow.com/questions/40291972/ssl-handshake-failure-with-java-version-1-7-0-79 –  Apr 24 '19 at 17:00
  • You may neet to collect more information, some instructions are here: https://blogs.oracle.com/java-platform-group/diagnosing-tls,-ssl,-and-https –  Apr 24 '19 at 17:02
  • Thanks a lot, Jakub. I have upgraded to JDK 1.8. Now, the connection has been established. – mathiyarasu.T Arasu Apr 30 '19 at 05:12

0 Answers0