使用流入站通道适配器spring boot实现从远程删除文件

时间:2018-03-27 16:36:11

标签: spring spring-boot

我试图通过实现流入站来从远程删除文件,但是在adviceChain实现之前连接正在关闭。

代码:

        2018-03-27 12:32:02.618  INFO 23216 --- [ask-scheduler-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=starsBatchJob]] completed with the following parameters: [{JobID=1522168322277}] and the following status: [COMPLETED]
    2018-03-27 12:32:02.618  INFO 23216 --- [ask-scheduler-1] c.f.u.config.ParentBatchConfiguration    : Job Status Completed
    2018-03-27 12:32:02.618  INFO 23216 --- [ask-scheduler-1] c.f.u.config.ParentBatchConfiguration    : Total time tokk for Stars Batch execution: 0 seconds.
    2018-03-27 12:32:02.618  INFO 23216 --- [ask-scheduler-1] c.f.u.config.ParentBatchConfiguration    : Batch Job lock is released
    2018-03-27 12:32:02.633  INFO 23216 --- [ask-scheduler-1] com.jcraft.jsch                          : Disconnecting from hpchd1e.hpc.ford.com port 22
    2018-03-27 12:32:02.633 ERROR 23216 --- [ask-scheduler-1] o.s.integration.handler.LoggingHandler   : org.springframework.messaging.MessagingException: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.MessagingException: Failed to execute on session; nested exception is org.springframework.core.NestedIOException: Failed to remove file: 2: No such file; nested exception is 2

无论我在哪里搜索每个人都建议实现ExpressionEvaluatingRequestHandlerAdvice,但它会让我低于错误。

Seq

1 个答案:

答案 0 :(得分:0)

我遇到了这个问题。我到远程文件的路径不正确。我需要结尾的/。由于路径是在Spel Expression中创建的,因此很难看到。您可以在handleMessage()方法中使用以下内容查看路径。

String remoteDirectory = (String) message.getHeaders().get("file_remoteDirectory");
String remoteFile = (String) message.getHeaders().get("file_remoteFile");

我确实必须使用上面注释掉的advice.setOnSuccessExpressionString("@template.remove(headers['file_remoteFile'])");而不是advice.setOnSuccessExpression"@template.remove(headers['file_remoteDirectory'] + headers['file_remoteFile'])"); 在文档https://docs.spring.io/spring-integration/reference/html/sftp.html#sftp-streaming中这是不正确的,这就是为什么我认为与此相关的人们会失去对文档的信任。但这似乎是唯一的错误。