3

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

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
SUNNY
  • 125
  • 1
  • 3
  • 13
  • You are mixing HTTP and HTTPS stuff. Is the mock service exposed through SSL by SOAP UI? You just need to change the address variable scheme to HTTPS. Is SOAP UI exposing the mock through HTTP? You have to use URLConnection instead of HttpsURLConnection – OttavioMonzione May 03 '16 at 12:41
  • No my mockservice is not exposed through SSL , How can I don that ? Please suggest me. – SUNNY May 03 '16 at 12:59

2 Answers2

10

If you want to use HTTPS then

The HTTPS (HTTP over SSL) protocol handler has its own set of properties:

https.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:

Java Networking and Proxies for HTTPS

Solution-1:

Add the following to the JAVA_OPTS environment variable:

-Djsse.enableSNIExtension=false

Restart your Crowd instance.

Resource Link:

https://confluence.atlassian.com/crowdkb/unrecognized-ssl-message-plaintext-connection-582877397.html

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:

Unrecognized SSL message, plaintext connection? Exception

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

You can go through this link also: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

Shaya
  • 2,792
  • 3
  • 26
  • 35
SkyWalker
  • 28,384
  • 14
  • 74
  • 132
  • Solution 3 ended up working for me. – Inaimathi May 02 '17 at 15:45
  • 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. – Balkrushna Patil Jul 06 '18 at 06:40
-2
java.net.URL url = new URL("http://localhost:8089");
java.net.URLConnection connection = url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "text/xml");
connection.setRequestMethod("GET");
connection.connect();