我偶尔会在标题中指出异常。有谁知道异常4的含义或记录的位置?我已经查看了与此相关的问题,并且我已经了解到例外2,这显然意味着"没有这样的文件"和例外3是"权限被拒绝"。但是,当我得到嵌套异常为4时,没有描述,所以我不确定这意味着什么。它只是一个通用的读取时间吗?这种情况很少发生,并且很难重现,因为我们的一些用户完全没有问题,而有些用户时不时会遇到这个问题。
org.springframework.core.NestedIOException: failed to read file /ftadv:D=IBM-037,C=UTF-8/__'MAIN.FRAME.DATASET'; nested exception is 4:
at org.springframework.integration.sftp.session.SftpSession.readRaw(SftpSession.java:143)
at org.springframework.integration.file.remote.session.CachingSessionFactory$CachedSession.readRaw(CachingSessionFactory.java:268)
at org.springframework.integration.file.remote.session.CachingSessionFactory$CachedSession.readRaw(CachingSessionFactory.java:268)
at com.my.package.FTPService.ftpStoreAuthData(FTPService.java:166)
at com.my.package.FTPService.ftpStoreNetAuthData(FTPService.java:59)
at com.my.package.FTPEndpoint.ftpStoreNetAuthData(FTPEndpoint.java:27)
如果有帮助,请点击此处。
@Configuration
class SftpConfiguration {
@Inject
private Environment env;
SessionFactory<LsEntry> getSftpSessionFactory() {
DefaultSftpSessionFactory sftpSessionFactory =
new DefaultSftpSessionFactory(Boolean.parseBoolean(env.getRequiredProperty("sftp.isSharedSession")));
sftpSessionFactory.setHost(env.getRequiredProperty("sftp.host"));
sftpSessionFactory.setPort(Integer.parseInt(env.getRequiredProperty("sftp.port")));
sftpSessionFactory.setUser(env.getRequiredProperty("sftp.id"));
sftpSessionFactory.setPrivateKey(new FileSystemResource(env.getRequiredProperty("sftp.keyPath")));
sftpSessionFactory.setPrivateKeyPassphrase(env.getRequiredProperty("sftp.passphrase"));
sftpSessionFactory.setTimeout(Integer.parseInt(env.getRequiredProperty("sftp.timeout")));
sftpSessionFactory.setAllowUnknownKeys(Boolean.parseBoolean(env.getRequiredProperty("sftp.allowUnknownKeys")));
return new CachingSessionFactory<LsEntry>(sftpSessionFactory);
}
CachingSessionFactory getCachingSessionFactory(){
CachingSessionFactory cachingSessionFactory = new CachingSessionFactory(getSftpSessionFactory());
cachingSessionFactory.setSessionWaitTimeout(Integer.parseInt(env.getRequiredProperty("sftp.sessionWaitTimeout")));
cachingSessionFactory.setPoolSize(Integer.parseInt(env.getRequiredProperty("sftp.poolSize")));
return cachingSessionFactory;
}
}
以下是调用代码的示例:
@Service
class FTPService {
private static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(FTPEndpoint.class);
private CachingSessionFactory cachingSessionFactory;
private String adviceString;
@Inject
private FTPService(SftpConfiguration sftpConfig) {
this.cachingSessionFactory = sftpConfig.getCachingSessionFactory();
this.adviceString = sftpConfig.getAdviceString();
}
private String ftpStoreAuthData() {
Session session = this.cachingSessionFactory.getSession();
String mainframeDataSet = "'MAIN.FRAME.DATASET'";
try(BufferedInputStream inputStream = new BufferedInputStream(session.readRaw(adviceString + mainframeDataSet));
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))
{
Stream<String> lines = reader.lines());
return doThingsWithFTPData(lines);
} catch (IOException ex) {
LogException.writeToFile(ex.getMessage(),ex.getStackTrace(), env.getProperty("sftp.exceptionsPath"));
}finally {
try {
if (session.isOpen()) {
session.finalizeRaw();
session.close();
}
}catch (IOException ioe){
System.out.println(ioe.getLocalizedMessage() + ioe.getCause().toString());
LogException.writeToFile(ioe.getMessage(),ioe.getStackTrace(), env.getProperty("sftp.exceptionsPath"));
throw new IOException();
}
}
return "test";
}
}