2

Java 1.7 + Apache Tomcat

I am consuming the Rest-Full Webservice, I have done below steps to add the certificates.

1) For Mozilla browser I added certificates, and I am able to get the response at REST-CLIENT.

2) Now I exported both the certificates (.crt files) from browser and added to ../lib/security/cacerts using keytool -import -alias cmd.

3) After that I tried to hit URL from java code but getting "javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure"

4) I added UnlimitedJCEPolicyJDK7 JAR's as well but didn't get any response.

Client Code :

URL url = new URL("https://myUrl/getAttributes");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/xml");
            Request reqBody = new Request();
            String input = reqBody.getXMLRequest();
            System.out.println(input);
            OutputStream os = conn.getOutputStream(); // Here it is getting failed

Stack-Trace :

javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
    at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
    at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1979)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1086)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1332)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1359)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1343)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185)
    at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1092)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl
user3676578
  • 213
  • 1
  • 5
  • 17

0 Answers0