问题
I am new to spring ftp integration. I want to download files from FTP server using dynamic parameters like host, username, password etc from database. I understand how to downloaded files using static parameters from properties file. I have succeeded in uploading files(ftp outbound) using dynamic parameters by referring to Dynamic FTP Sample example. Please, help me configuring "inbound dynamic ftp" .
I have successfully implemented this but I am facing few new issue with this solution.
Scenario: Say the ftp server host name is "ftp.foo.in" and have a folder structure like
/ (root) |- countries |- states |- cities
Problems: 1) On accessing sub folders, it throws Unknownhostexception. For Example, if I try to connect with host name="ftp.foo.in/countries/states", then it throws exception as follows:
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
Where as if I try to access sub folders by using org.apache.commons.net.ftp.FtpClient's changeWorkingDirectory(), it successfully executes.
2) If I pass credentials like username/password wrong, then it will display the stack trace infinitely. I want that spring integration module, should try to resolve with wrong credentials once and print stack trace once only . I debugged it to inner code and found cause. Actually, when spring integration module fail to establish condition , it prints stack trace and it internally reschedule the attempt to connect with same credentials(in this case wrong credentials) continuously. Have I missed out any configuration regarding this?
回答1:
See this spring forum thread Dynamic Inbound Channel Adapter creation and follow its links (specifically this one).
Essentially, you make the main context the parent of the (s)ftp context so the inbound adapter can reference the channel.
来源:https://stackoverflow.com/questions/20370127/how-to-configure-spring-integration-ftp-for-dynamic-inbound