从eclipse插件中连接到HTTPS会抛出异常

时间:2014-12-15 20:15:17

标签: java eclipse ssl https eclipse-plugin

我的插件中有一段代码如下:

    String url = "https://...";

    HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
    con.setDoOutput(true);
    con.connect();
    OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
    writer.flush();
    writer.close();

当我在独立的Java应用程序中使用它时,此代码非常有效。但是当我尝试从插件中运行时,它会引发以下异常:

javax.net.ssl.SSLException: Unsupported record version SSLv2Hello
    at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)
    at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:565)
    at sun.security.ssl.InputRecord.read(InputRecord.java:529)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
    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.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at test.plugin.Activator.testSSLConnection(Activator.java:57)
    at test.plugin.Activator.start(Activator.java:42)

我应该配置什么来使代码在插件中工作? 我在这里或eclipse论坛上没有找到与SSL相关的eclipse插件上下文中的任何解决方案。

1 个答案:

答案 0 :(得分:0)

找到解决此问题的方法:

服务器在Java 7上运行,而客户端在Java 8上运行。 一旦我将我的eclipse运行时切换到Java 7,问题就解决了。