I am completely new to Spring Integration. Following is my requirement :
I have to poll a given location (say a directory in interval of 5 sec.) for a file (with a given pattern - defined by regex.). IF the file is found that I have to perform certain operation(s) on the file (say log a message "File found", save the file to another location, etc.) and if the file is NOT found then the program needs to log a message say - "Polling interval 5 sec ... File not found". The program also needs to poll for 9 hrs. and after that it should STOP polling i.e. program should QUIT.
I would like to take care of various error scenarios such as:
1) Folder not present: What would happen if the folder (directory) which is being polled for the file is not present? My latest code is as follows:
<int-event:inbound-channel-adapter
channel="contextStartedEventChannelChannel" event- types="org.springframework.context.event.ContextRefreshedEvent"
payload-expression="new java.io.File('${myapp.incomingFile.path}').exists()" />
<int:router input-channel="contextStartedEventChannelChannel"
expression="payload">
<int:mapping value="true" channel="trueChannel" />
<int:mapping value="false" channel="falseChannel" />
</int:router>
<int:outbound-channel-adapter id="trueChannel"
expression="@'incomingFiles.adapter'.start()" />
<int:outbound-channel-adapter id="falseChannel"
ref="errorTracker" method="processError" />
Code for Inbound-channel-adapter:
<int-file:inbound-channel-adapter id="incomingFiles"
directory="file:${myapp.incomingFile.path}" prevent-duplicates="true"
filename-regex="${ETD.filenameRegex}" auto-create-directory="false"
auto-startup="false">
Issues:
1) But now what's happening is that when I delete the polled directory purposefully then as expected we are getting an exception but its coming as a stacktrace on the console and its not going on an error channel.
2) Currently we are only taking care of one error scenario i.e. if the polled directory is not present. I would also want to implement other error scenarios such as network down, etc. , etc. and would like to just show a message on the logger (i.e. pass on the error channel) and gracefully exit the program.
Please do kindly suggest what's wrong.
Following is the exception which I am getting:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingFiles.adapter': Cannot resolve reference to bean 'incomingFiles.adapter.source' while setting bean property 'source'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingFiles.adapter.source': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Source directory [C:\TEMP\incomingFile] does not exist. at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:681) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) at com.jefferies.fileutility.App.main(App.java:31) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'incomingFiles.adapter.source': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalArgumentException: Source directory [C:\TEMP\incomingFile] does not exist. at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:151) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103) at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1514) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:252) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320) ... 15 more Caused by: java.lang.IllegalArgumentException: Source directory [C:\TEMP\incomingFile] does not exist. at org.springframework.util.Assert.isTrue(Assert.java:65) at org.springframework.integration.file.FileReadingMessageSource.onInit(FileReadingMessageSource.java:237) at org.springframework.integration.context.IntegrationObjectSupport.afterPropertiesSet(IntegrationObjectSupport.java:133) at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.initSource(FileReadingMessageSourceFactoryBean.java:170) at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.getObject(FileReadingMessageSourceFactoryBean.java:111) at org.springframework.integration.file.config.FileReadingMessageSourceFactoryBean.getObject(FileReadingMessageSourceFactoryBean.java:40) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:144) ... 20 more