我是Spring Integration的新手,我需要建立一个只接受GET
和PUT
命令的服务器的FTP连接。
我配置了FtpOutboundGateway
和@MessagingGateway
,它实际上正在运行。
然而FtpOutboundGateway
设置
@Bean
@ServiceActivator(inputChannel = "ftpFetchFile")
public MessageHandler getFile() {
FtpOutboundGateway gateway = new FtpOutboundGateway(this.ftpSessionFactory(), "get", "payload");
gateway.setLocalDirectoryExpression(EXPRESSION_PARSER.parseExpression("#remoteDirectory"));
gateway.setFileExistsMode(FileExistsMode.REPLACE);
return gateway;
}
也会在LS
之前执行GET
命令。这实际上是一种很好的方式,证明文件存在,但是当服务器正在动态创建文件时,LS
永远不会返回任何现有文件,因此在{{1}的MessagingException中运行}:
org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.get(Message<?>, Session<F>, String, String, String, boolean)
有没有办法检索只有Ftp failure occurred in gateway sendAndReceive: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.MessagingException: someFile.txt is not a file
的文件?
答案 0 :(得分:0)
如果您有此类限制且只能执行GET
,请考虑使用FtpOutboundGateway
MessageSessionCallback
并使用@Bean
@ServiceActivator(inputChannel = "ftpFetchFile")
public MessageHandler getFile() {
return new FtpOutboundGateway(this.ftpSessionFactory(),
(session, requestMessage) -> {
// Call Session.read() or Session.readRaw() and return the result of reading
});
}
Reader in = new FileReader("path/to/file.csv");
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in);
for (CSVRecord record : records) {
String lastName = record.get("Last Name");
String firstName = record.get("First Name");
}