HttpsURLConnection请求上的javax.net.ssl.SSLException

HttpsURLConnection请求上的javax.net.ssl.SSLException,java,http,jakarta-ee,https,ftp4j,Java,Http,Jakarta Ee,Https,Ftp4j,在重命名ftp服务器目录中的文件之后,我正在尝试调用java应用程序中的https url 该文件已重命名,https url请求已成功,但我收到一个奇怪的异常,该异常与在我的cacerts文件中导入的证书有关 重命名ftp目录中的文件,然后发出https url请求的代码如下: ... FTPClient client = null; try { client = Ftp4jUtility.ftpsConnect1(SERVER_MACHINE, PORT, SERVER_USERNA

在重命名ftp服务器目录中的文件之后,我正在尝试调用java应用程序中的https url

该文件已重命名,https url请求已成功,但我收到一个奇怪的异常,该异常与在我的cacerts文件中导入的证书有关

重命名ftp目录中的文件,然后发出https url请求的代码如下:

...
FTPClient client = null;
try {
    client = Ftp4jUtility.ftpsConnect1(SERVER_MACHINE, PORT, SERVER_USERNAME, SERVER_PASSWORD);          
    client.rename(oldDir, newDir);
    renameStatus=true;
    String url = config.getExtractZipUrl()+stdDet.getStudyDetailsCaseId(tmpNewFile.trim());
    try {
            JavaHttpsUrlConnectionReader(url);
        } catch (Exception ex) {
            Logger.getLogger(TranferFileFtp4j.class.getName()).log(Level.ERROR, null, ex);
        } 

        client.logout();
        client.disconnect(true);

    } catch (IllegalStateException ex) {
        log.info("Failed to rename: " + oldDir);
        Logger.getLogger(TranferFileFtp4j.class.getName()).log(Level.ERROR, null, ex);

    } catch (IOException | FTPIllegalReplyException | FTPException ex) {
        log.info("Failed to rename: " + oldDir);
        Logger.getLogger(TranferFileFtp4j.class.getName()).log(Level.ERROR, null, ex);

    } finally {
        if (client.isConnected()) {
            try {
                try {
                    client.logout();
                    client.disconnect(true);
                } catch (IllegalStateException | FTPIllegalReplyException | FTPException ex) {
                    Logger.getLogger(TranferFileFtp4j.class.getName()).log(Level.ERROR, null, ex);
                }                    
            } catch (IOException ex) {
                Logger.getLogger(TranferFileFtp4j.class.getName()).log(Level.ERROR, null, ex);
            }
        }

    }
return renameStatus;
在我的日志中,我发现:

2015-03-05 13:09:04 ERROR TranferFileFtp4j:398 - 
javax.net.ssl.SSLException: Unsupported record version Unknown-53.49
at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)    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:532)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:911)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:127)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:112)
at java.io.InputStreamReader.read(InputStreamReader.java:168)
at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:105)
at it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunicationChannel.java:142)
at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommunicationChannel.java:187)
at it.sauronsoftware.ftp4j.FTPClient.disconnect(FTPClient.java:1133)
at com.npap.network.TranferFileFtp4j.renameFileFtps1(TranferFileFtp4j.java:390)
at com.npap.utils.ProcessDicomFiles.sendZippFiles(ProcessDicomFiles.java:195)
at com.npap.scheduler.MainJob.execute(MainJob.java:84)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
2015-03-05 13:09:04 ERROR TranferFileFtp4j:415 - 
java.lang.IllegalStateException: Client not authenticated
at it.sauronsoftware.ftp4j.FTPClient.logout(FTPClient.java:1406)
at com.npap.network.TranferFileFtp4j.renameFileFtps1(TranferFileFtp4j.java:412)
at com.npap.utils.ProcessDicomFiles.sendZippFiles(ProcessDicomFiles.java:195)
at com.npap.scheduler.MainJob.execute(MainJob.java:84)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573)
下面的代码也非常简单,这使得https url请求变得非常简单:

public void JavaHttpsUrlConnectionReader(String myUrl) throws Exception {
    URL url = null;
    BufferedReader reader = null;
    StringBuilder stringBuilder;
    try {
        url = new URL(myUrl);
        HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();

        // just want to do an HTTP GET here
        connection.setRequestMethod("GET");
        // give it 15 seconds to respond
        connection.setReadTimeout(15*1000);
        connection.connect();
        // read the output from the server
        reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        stringBuilder = new StringBuilder();

        String line = null;
        while ((line = reader.readLine()) != null)
        {
          stringBuilder.append(line + "\n");
        }
        //return stringBuilder.toString();
    }
    catch (Exception e)
    {
      e.printStackTrace();
      throw e;
    }
    finally
    {
        // close the reader; this can throw an exception too, so
        // wrap it in another try/catch block.
        if (reader != null)
        {
          try
          {
            reader.close();
          }
          catch (IOException ioe)
          {
            ioe.printStackTrace();
          }
        }
    }

}
为什么我会收到:

javax.net.ssl.SSLException: Unsupported record version Unknown-53.49
at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)    at sun.security.ssl.InputRecord.checkRecordVersion(InputRecord.java:552)
如果您进一步查看:

java.lang.IllegalStateException: Client not authenticated
at it.sauronsoftware.ftp4j.FTPClient.logout(FTPClient.java:1406)
实际上,我的代码中引用到日志的第390行是我试图:

client.disconnecttrue


因此,当我试图从ftp会话断开连接时,我收到了异常。有人知道我为什么会收到这个异常吗?

您使用的是哪个Java版本?也许你可以试试

最后看起来

client.logout();
之前:

client.disconnet(true);
导致异常的原因是:

java.lang.IllegalStateException: Client not authenticated
at it.sauronsoftware.ftp4j.FTPClient.logout(FTPClient.java:1406)
委员会:

是由于https请求HttpsURLConnection的读取超时不足造成的:

HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(15*1000);
connection.connect();

15秒是不够的。增加到60,解决了…

Java8,我无法切换到其他版本。
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setReadTimeout(15*1000);
connection.connect();