在重命名 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.disconnect(true);
因此,当我尝试从 ftp 会话断开连接时,我收到了异常。有人知道为什么我会收到此异常吗?