本文介紹了使用 Java DSL 成功進行 ftp 傳輸后移動文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我已經使用 spring-integration java dsl 定義了一個流程來 ftp 傳輸文件,處理它,然后將其傳輸回存檔"目錄,最后將其移動到本地存檔目錄中.這是很容易"的事情:
I've defined a flow using spring-integration java dsl to ftp transfer a file, handle it, then transfer it back in an "archive" dir, and at last move it in a local archive dir. Which is something "quite easy" as:
@Bean
public IntegrationFlow ftpInboundFlow() {
if (ftpProperties.getEnabled() == false) {
return null;
}
logger.trace("Starting ftp flow");
return IntegrationFlows
.from(source -> source.ftp(ftpSessionFactory()).deleteRemoteFiles(true).preserveTimestamp(true)
.filter(compositeWithAcceptOnceFilter()) .remoteDirectory(ftpProperties.getRemoteDirectory())
.localDirectory(new File(ftpProperties.getLocalDirectory())).autoCreateLocalDirectory(true),
consumer -> consumer.id("ftpInboundAdapter")) /* Fine from() */
.handle(new GenericHandler<File>() {
@Override
@Transactional
public Object handle(File payload, Map<String, Object> headers) {
logger.debug("Data arrived {} {}", payload, payload.getClass().getName());
return payload;
}
}) /* Fine GenericHandler */
.handleWithAdapter(a -> a.ftp(ftpSessionFactory())
.remoteDirectory(ftpProperties.getRemoteArchiveDirectory()).autoCreateDirectory(true))
.get();
}
如果我追加
.handleWithAdapter(a -> a.file("'" + ftpProperties.getLocalArchiveDirectory() + "'")
.autoCreateDirectory(true).deleteSourceFiles(true))
在 ftp 適配器配置后,bean 初始化程序回復以下錯誤消息:
after the ftp adapter configuration the bean initializer replies with the following error message:
Caused by: org.springframework.beans.factory.BeanCreationException: The 'currentComponent' (org.springframework.integration.file.remote.handler.FileTransferringMessageHandler@80bfa9d) is a one-way 'MessageHandler' and it isn't appropriate to configure 'outputChannel'. This is the end of the integration flow.
我應該如何解決它?
推薦答案
作為一種解決方法,我重構了我的代碼,放棄了文件適配器:
As a workaround I refactored my code in giving up with the file adapter:
@Bean
public IntegrationFlow ftpInboundFlow() {
return IntegrationFlows
.from(source -> source.ftp(ftpSessionFactory()).deleteRemoteFiles(true).preserveTimestamp(true)
.filter(compositeWithAcceptOnceFilter()) .remoteDirectory(ftpProperties.getRemoteDirectory())
.localDirectory(new File(ftpProperties.getLocalDirectory())).autoCreateLocalDirectory(true),
consumer -> consumer.id("ftpInboundAdapter")) /* Fine from() */
.handle(new GenericHandler<File>() {
@Override
@Transactional
public Object handle(File payload, Map<String, Object> headers) {
logger.debug("Data arrived {} {}", payload, payload.getClass().getName());
/* handle file content here ... */
/* ... then move it to archive */
File dstFile = new File("archive", payload);
FileUtils.moveFile(payload, dstFile);
return dstFile;
}
}) /* Fine GenericHandler */
/* Archive the remote file */
.handleWithAdapter(a -> a.ftp(ftpSessionFactory())
.remoteDirectory(ftpProperties.getRemoteArchiveDirectory()).autoCreateDirectory(true))
.get();
}
這篇關于使用 Java DSL 成功進行 ftp 傳輸后移動文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!