Sunday, November 19, 2017

Open connection failed: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

Question:

I have created a a rest mockservice using SOAP UI. And I am trying to connect it from my java class. But It is failing with error
Open connection failed: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source)
sun.security.ssl.InputRecord.read(Unknown Source)
sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
I am not sure where I am going wrong.
Below is the code -
java.net.URL url = new URL(null, address,new sun.net.www.protocol.https.Handler());
connection = (javax.net.ssl.HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestMethod("GET");
connection.connect();
And The URL I am trying to connect is - http://localhost:8089

Answer:


If you want to use HTTPS then
The https (http over SSL) protocol handler has its own set of properties:
htttps.proxyHost
https.proxyPort
As you probably guessed these work in the exact same manner as their http counterparts, so we won't go into much detail except to mention that the default port number, this time, is 443 and that for the "non proxy hosts" list, the HTTPS protocol handler will use the same as the http handler (i.e. http.nonProxyHosts).

Resource Link:

Solution-1:

Add the following to the JAVA_OPTS environment variable:
-Djsse.enableSNIExtension=false
Restart your Crowd instance.

Resource Link:

Solution-2:

I think this is due to the connection established with the client machine is not secure. It is due to the fact that you are talking to an HTTP server, not an HTTPS server. Probably you didn't use the correct port number for HTTPS.
Credit goes to @EJP

Resource Link:

Solution-3:

If you use SMTP domain name, then mail.smtp.socketFactory.fallback properites need to be true.
props.put("mail.smtp.socketFactory.fallback", "true"); // Make it true
Resource Link: https://stackoverflow.com/a/37005249/2293534

No comments:

Post a Comment