我是刚开始使用ftp集成的新手。我想使用数据库中的主机,用户名,密码等动态参数从FTP服务器下载文件。我了解如何使用属性文件中的静态参数下载文件。我已成功通过引用Dynamic FTP Sample示例使用动态参数上传文件( ftp outbound )。 请帮我配置“入站动态ftp”。
我已经成功实现了这一点,但我对这个解决方案几乎没有新的问题。
场景:假设ftp服务器主机名是“ftp.foo.in”并且具有类似
的文件夹结构/ (root) |- countries |- states |- cities
问题: 1)在访问子文件夹时,它会抛出 Unknownhostexception 。例如,如果我尝试连接主机名=“ftp.foo.in/countries/states”,那么它会抛出异常,如下所示:
ERROR: org.springframework.integration.handler.LoggingHandler - java.lang.IllegalStateException: failed to create FTPClient
at org.springframework.integration.ftp.session.AbstractFtpSessionFactory.getSession(AbstractFtpSessionFactory.java:139)
at com.xxx.yyy.zzz.FTPInboundRecursiveFileSynchronizer.synchronizeToLocalDirectory(Unknown Source)
at com.xxx.yyy.zzz.FTPInboundRecursiveFileSynchronizer.synchronizeToLocalDirectory(Unknown Source)
at org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource.receive(AbstractInboundFileSynchronizingMessageSource.java:146)
at org.springframework.integration.endpoint.SourcePollingChannelAdapter.receiveMessage(SourcePollingChannelAdapter.java:111)
at org.springframework.integration.endpoint.AbstractTransactionSynchronizingPollingEndpoint.doPoll(AbstractTransactionSynchronizingPollingEndpoint.java:67)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:146)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$1.call(AbstractPollingEndpoint.java:144)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:236)
at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
at org.springframework.integration.util.ErrorHandlingTaskExecutor.execute(ErrorHandlingTaskExecutor.java:49)
at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller.run(AbstractPollingEndpoint.java:231)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:53)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.net.UnknownHostException: ftp.foo.in/countries/states
at java.net.InetAddress.getAllByName0(InetAddress.java:1215)
at java.net.InetAddress.getAllByName(InetAddress.java:1127)
at java.net.InetAddress.getAllByName(InetAddress.java:1063)
at java.net.InetAddress.getByName(InetAddress.java:1013)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:189)
at org.springframework.integration.ftp.session.AbstractFtpSessionFactory.createClient(AbstractFtpSessionFactory.java:152)
at org.springframework.integration.ftp.session.AbstractFtpSessionFactory.getSession(AbstractFtpSessionFactory.java:136)
... 22 more
如果我尝试使用org.apache.commons.net.ftp.FtpClient的changeWorkingDirectory()访问子文件夹,它就会成功执行。
2)如果我传递了像用户名/密码错误的凭据,那么它将显示堆栈跟踪无限。我想要那个spring集成模块,应该尝试用错误的凭证解析一次并且只打印一次堆栈跟踪。 我把它调试到内部代码并找到原因。实际上,当spring集成模块无法建立条件时,它会打印堆栈跟踪,并在内部重新安排尝试连续使用相同的凭据(在这种情况下是错误的凭据)进行连接。我错过了有关此的任何配置吗?
答案 0 :(得分:2)
请参阅此春季论坛帖子Dynamic Inbound Channel Adapter creation并按照其链接(特别是this one)。
基本上,您将主上下文作为(s)ftp上下文的父级,因此入站适配器可以引用该通道。