我已经使用SOAP UI创建了一个rest模拟服务。我正试图从我的java类中连接它。但它失败了,错误
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)
我不确定哪里出了问题。
以下是代码-
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();
我尝试连接的URL是-http://localhost:8089
如果您想使用HTTPS,则
HTTPS(HTTP over SSL)协议处理程序有自己的一组属性:
https.proxyHost https.proxyPort
正如你可能猜到的,这些工作的方式与它们完全相同http对应,所以我们除了提到之外就不谈太多细节了默认端口号,这次是443,对于代理主机"列表,HTTPS协议处理程序将使用与http处理程序(即http.nonProxyHosts)。
资源链接:
HTTPS 的Java网络和代理
解决方案1:
将以下内容添加到JAVA_OPTS
环境变量中:
-Djsse.enableSNIExtension=false
重新启动群组实例。
资源链接:
https://confluence.atlassian.com/crowdkb/unrecognized-ssl-message-plaintext-connection-582877397.html
解决方案2:
我认为这是由于与客户端机器建立的连接不安全。这是因为您所使用的是HTTP服务器,而不是HTTPS服务器。可能您没有为HTTPS使用正确的端口号。
信用归于@EJP
资源链接:
无法识别的SSL消息,明文连接?异常
解决方案-3:
如果使用SMTP域名,则mail.smtp.socketFactory.fallback
属性必须为true。
props.put("mail.smtp.socketFactory.fallback", "true"); // Make it true
您也可以通过此链接:javax.net.ssl.SSLException:无法识别的ssl消息,明文连接?
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();