Announcement Announcement Module
Collapse
No announcement yet.
FlatFileItemReader where resource type is ftp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FlatFileItemReader where resource type is ftp

    Hi,

    I am having issues in reading file from the one of our ftp server. If I replace the FTP file with local file system it works fine. Can you please help me in resolving the following issue

    Below is my code:

    <beans:bean id="itemReader" class="org.springframework.batch.item.file.FlatFil eItemReader">
    <!-- <beansroperty name="resource" value="file:C:/batch/lockbox/PRDReport.csv"/> -->
    <beansroperty name="resource" value="ftp://userwd@server:21/apps/eai/spring_apps/PRDReport.csv"/>

    I am getting following error:

    org.springframework.batch.item.ItemStreamException : Failed to initialize the reader
    at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.open(AbstractItemCou ntingItemStreamItemReader.java:139)
    at org.springframework.batch.item.support.CompositeIt emStream.open(CompositeItemStream.java:98)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.open(TaskletStep.java:379)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:195)
    at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
    at org.springframework.batch.core.job.flow.FlowJob.ac cess$0(FlowJob.java:1)
    at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:135)
    at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:103)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:105)
    at org.springframework.sample.batch.example.ExampleJo bConfigurationTests.testLaunchJob(ExampleJobConfig urationTests.java:50)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.test.context.junit4.SpringTest Method.invoke(SpringTestMethod.java:160)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.runTestMethod(SpringMethodRoadie.java:233 )
    at org.springframework.test.context.junit4.SpringMeth odRoadie$RunBeforesThenTestThenAfters.run(SpringMe thodRoadie.java:333)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.runWithRepetitions(SpringMethodRoadie.jav a:217)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.runTest(SpringMethodRoadie.java:197)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.run(SpringMethodRoadie.java:143)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.invokeTestMethod(SpringJUnit4ClassRu nner.java:160)
    at org.junit.internal.runners.JUnit4ClassRunner.runMe thods(JUnit4ClassRunner.java:51)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run (JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotec ted(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtecte d(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(J Unit4ClassRunner.java:42)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
    Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [ftp:ftp://user:pwd@server:21/apps/ea...PRDReport.csv]
    at org.springframework.batch.item.file.FlatFileItemRe ader.doOpen(FlatFileItemReader.java:245)
    at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.open(AbstractItemCou ntingItemStreamItemReader.java:137)
    ... 38 more

  • #2
    @SpringBatchGuy,

    It seems like "org.springframework.core.io.URLResource" is what you need.

    Instead of just injecting a String as a resource that represents your ftp URL, try to inject a URLResource. Here is how you can create it:

    Code:
    new URLResource(new URL("ftp://user:pwd@server:21/apps/ea...PRDReport.csv"));
    I have not tested it with "FlatFileItemReader", but that should create a "live" resource that will exist.

    Please post back and let me know if it worked

    P.S. You can also ftp the file over before reading, if that is of course and option, using jscape or similar tools.

    Comment


    • #3
      The original snippet you posted should work, but the error message doesn't match it:

      URL [ftp:ftp://user:pwd@server:21/apps/ea...PRDReport.csv]
      This is not a valid URL, so it's not surprising it didn't work. You probably just need to check your configuration carefully.
      Last edited by Dave Syer; Dec 4th, 2009, 02:39 AM. Reason: noparse

      Comment


      • #4
        Hi Dave,

        While changing the username and pwd of actual system .. I have copy pasted the URL in exception by removing actual URL.

        But still I get exception while trying above snippet.

        2009-12-04 08:38:52,677 INFO [org.springframework.test.context.TestContextManage r] - <@TestExecutionListeners is not present for class [class org.springframework.sample.batch.example.ExampleJo bConfigurationTests]: using defaults.>
        2009-12-04 08:38:54,801 INFO [org.springframework.beans.factory.xml.XmlBeanDefin itionReader] - <Loading XML bean definitions from class path resource [application-context.xml]>
        2009-12-04 08:38:56,863 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Overriding bean definition for bean 'SFDC_OP_UPD_00': replacing [Generic bean: class [org.springframework.batch.core.job.flow.support.Si mpleFlow]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.batch.core.configuration.xml.J obParserJobFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]>
        2009-12-04 08:38:57,004 INFO [org.springframework.context.support.GenericApplica tionContext] - <Refreshing org.springframework.context.support.GenericApplica tionContext@fa3ac1: display name [org.springframework.context.support.GenericApplica tionContext@fa3ac1]; startup date [Fri Dec 04 08:38:56 EST 2009]; root of context hierarchy>
        2009-12-04 08:38:57,004 INFO [org.springframework.context.support.GenericApplica tionContext] - <Bean factory for application context [org.springframework.context.support.GenericApplica tionContext@fa3ac1]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@110fe28>
        2009-12-04 08:38:58,754 INFO [org.springframework.beans.factory.config.PropertyP laceholderConfigurer] - <Loading properties file from class path resource [batch.properties]>
        2009-12-04 08:38:59,191 INFO [org.springframework.beans.factory.support.DefaultL istableBeanFactory] - <Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@110fe28: defining beans [org.springframework.batch.core.scope.internalStepS cope,org.springframework.beans.factory.config.Cust omEditorConfigurer,org.springframework.batch.core. configuration.xml.CoreNamespacePostProcessor,readL ogTableData11,readLogTableDataNew,SFDC_OP_UPD_00,i temReader,lineMapper,lineReader,itemWriter,jobLaun cher,jobRepository,promotionListener,dataSource,tr ansactionManager,placeholderProperties,dataSourceI nitializer,org.springframework.context.annotation. internalCommonAnnotationProcessor,org.springframew ork.context.annotation.internalAutowiredAnnotation Processor,org.springframework.context.annotation.i nternalRequiredAnnotationProcessor]; root of factory hierarchy>
        2009-12-04 08:39:01,581 INFO [org.springframework.batch.core.repository.support. JobRepositoryFactoryBean] - <No database type set, using meta data indicating: HSQL>
        2009-12-04 08:39:03,393 INFO [org.springframework.batch.core.launch.support.Simp leJobLauncher] - <No TaskExecutor has been set, defaulting to synchronous executor.>
        2009-12-04 08:39:04,034 INFO [org.springframework.batch.core.launch.support.Simp leJobLauncher] - <Job: [FlowJob: [name=SFDC_OP_UPD_00]] launched with the following parameters: [{}]>
        2009-12-04 08:39:04,034 DEBUG [org.springframework.batch.core.job.AbstractJob] - <Job execution starting: JobExecution: id=0, startTime=null, endTime=null, lastUpdated=Fri Dec 04 08:39:03 EST 2009, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=0, JobParameters=[{}], Job=[SFDC_OP_UPD_00]]>
        2009-12-04 08:39:04,065 DEBUG [org.springframework.batch.core.job.flow.support.Si mpleFlow] - <Resuming state=readLogTableData11 with status=UNKNOWN>
        2009-12-04 08:39:04,065 DEBUG [org.springframework.batch.core.job.flow.support.Si mpleFlow] - <Handling state=readLogTableData11>
        2009-12-04 08:39:04,065 INFO [org.springframework.batch.core.job.AbstractJob] - <Executing step: [TaskletStep: [name=readLogTableData11]]>
        2009-12-04 08:39:04,065 DEBUG [org.springframework.batch.core.step.AbstractStep] - <Executing: id=0>
        2009-12-04 08:39:04,315 ERROR [org.springframework.batch.core.step.AbstractStep] - <Encountered an error executing the step>
        org.springframework.batch.item.ItemStreamException : Failed to initialize the reader
        at org.springframework.batch.item.support.AbstractIte mCountingItemStreamItemReader.open(AbstractItemCou ntingItemStreamItemReader.java:139)
        at org.springframework.batch.item.support.CompositeIt emStream.open(CompositeItemStream.java:98)
        at org.springframework.batch.core.step.tasklet.Taskle tStep.open(TaskletStep.java:379)
        at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:195)
        at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
        at org.springframework.batch.core.job.flow.FlowJob.ac cess$0(FlowJob.java:1)
        at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:135)
        at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
        at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
        at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
        at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:103)
        at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
        at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
        at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
        at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:105)
        at org.springframework.sample.batch.example.ExampleJo bConfigurationTests.testLaunchJob(ExampleJobConfig urationTests.java:50)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.test.context.junit4.SpringTest Method.invoke(SpringTestMethod.java:160)
        at org.springframework.test.context.junit4.SpringMeth odRoadie.runTestMethod(SpringMethodRoadie.java:233 )
        at org.springframework.test.context.junit4.SpringMeth odRoadie$RunBeforesThenTestThenAfters.run(SpringMe thodRoadie.java:333)
        at org.springframework.test.context.junit4.SpringMeth odRoadie.runWithRepetitions(SpringMethodRoadie.jav a:217)
        at org.springframework.test.context.junit4.SpringMeth odRoadie.runTest(SpringMethodRoadie.java:197)
        at org.springframework.test.context.junit4.SpringMeth odRoadie.run(SpringMethodRoadie.java:143)
        at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.invokeTestMethod(SpringJUnit4ClassRu nner.java:160)
        at org.junit.internal.runners.JUnit4ClassRunner.runMe thods(JUnit4ClassRunner.java:51)
        at org.junit.internal.runners.JUnit4ClassRunner$1.run (JUnit4ClassRunner.java:44)
        at org.junit.internal.runners.ClassRoadie.runUnprotec ted(ClassRoadie.java:27)
        at org.junit.internal.runners.ClassRoadie.runProtecte d(ClassRoadie.java:37)
        at org.junit.internal.runners.JUnit4ClassRunner.run(J Unit4ClassRunner.java:42)
        at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
        at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:46)
        at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
        at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
        Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [ftp://user:pwd@eaiorasbx01xxxx:21/ap...PRDReport.csv]
        at org.springframework.batch.item.file.FlatFileItemRe ader.doOpen(FlatFileItemReader.java:245)

        Comment


        • #5
          Originally posted by litius View Post
          @SpringBatchGuy,

          It seems like "org.springframework.core.io.URLResource" is what you need.

          Instead of just injecting a String as a resource that represents your ftp URL, try to inject a URLResource. Here is how you can create it:

          Code:
          new URLResource(new URL("ftp://user:pwd@server:21/apps/ea...PRDReport.csv"));
          I have not tested it with "FlatFileItemReader", but that should create a "live" resource that will exist.

          Please post back and let me know if it worked

          P.S. You can also ftp the file over before reading, if that is of course and option, using jscape or similar tools.
          Hi Litius,

          Thanks for your response.

          I have tested with URLResource and I got the same exception.

          I have coded like below:

          <beans:bean id="itemReader" class="org.springframework.batch.item.file.FlatFil eItemReader">
          <beansroperty name="resource" ref="resource" />
          ......

          <beans:bean id="resource" class="org.springframework.core.io.UrlResource">
          <beans:constructor-arg value="ftp://abc:abc@abc:21/apps/eaidbg1/spring_apps/Archive/External/PRDReport.csv"/>
          </beans:bean>

          I think you are correct. I will FTP my file to local directory where my batch process is running and that will solve my problem.

          Thanks again for your suggestions

          Comment


          • #6
            Originally posted by Dave Syer View Post
            The original snippet you posted should work, but the error message doesn't match it:



            This is not a valid URL, so it's not surprising it didn't work. You probably just need to check your configuration carefully.
            Hi Dave,

            While editing the actual values in the exception I have pasted the URL which I was configured. I am sure that the above bean configuration which I have mentioned is correct and it is not working.

            I got the following snippet from Batch process document.

            "In complex batch environments the directory structures are often managed by the EAI infrastructure
            where drop zones for external interfaces are established for moving files from ftp locations to batch processing locations and vice versa. File moving utilities are beyond the scope of the spring batch architecture but it is not unusual for batch job streams to include file moving utilities as steps in the
            job stream"


            I think it's good idea to move the files from FTP location to local server then start batch process.

            Please let me know if you have any other suggestions.

            Regards,
            Rama

            Comment


            • #7
              Please use [code][/code] tags to post code and stack traces. If you ignore these hints you might find that your posts eventually just get ignored.

              Comment


              • #8
                Sorry .. new to this type of forums

                Below is my application context config file:

                Code:
                <beans:bean id="itemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
                		<beans:property name="resource" ref="resource" />
                		......
                
                <beans:bean id="resource" class="org.springframework.core.io.UrlResource">
                		<beans:constructor-arg value="ftp://abc:abc@abc:21/apps/eaidbg1/spring_apps/Archive/External/PRDReport.csv"/>
                </beans:bean>
                I go the following Exception:

                Code:
                2009-12-04 09:08:40,665 INFO [org.springframework.test.context.TestContextManager] - <@TestExecutionListeners is not present for class [class org.springframework.sample.batch.example.ExampleJobConfigurationTests]: using defaults.>
                2009-12-04 09:08:40,790 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [application-context.xml]>
                2009-12-04 09:08:41,040 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Overriding bean definition for bean 'SFDC_OP_UPD_00': replacing [Generic bean: class [org.springframework.batch.core.job.flow.support.SimpleFlow]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.batch.core.configuration.xml.JobParserJobFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]>
                2009-12-04 09:08:41,056 INFO [org.springframework.context.support.GenericApplicationContext] - <Refreshing [email protected]f375: display name [[email protected]f375]; startup date [Fri Dec 04 09:08:41 EST 2009]; root of context hierarchy>
                2009-12-04 09:08:41,056 INFO [org.springframework.context.support.GenericApplicationContext] - <Bean factory for application context [[email protected]f375]: org.springframework.beans.factory.support.DefaultListableBeanFactory@2ba11b>
                2009-12-04 09:08:41,165 INFO [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] - <Loading properties file from class path resource [batch.properties]>
                2009-12-04 09:08:41,228 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2ba11b: defining beans [org.springframework.batch.core.scope.internalStepScope,org.springframework.beans.factory.config.CustomEditorConfigurer,org.springframework.batch.core.configuration.xml.CoreNamespacePostProcessor,readLogTableData11,readLogTableDataNew,SFDC_OP_UPD_00,itemReader,resource,lineMapper,lineReader,itemWriter,jobLauncher,jobRepository,promotionListener,dataSource,transactionManager,placeholderProperties,dataSourceInitializer,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor]; root of factory hierarchy>
                2009-12-04 09:08:41,634 INFO [org.springframework.batch.core.repository.support.JobRepositoryFactoryBean] - <No database type set, using meta data indicating: HSQL>
                2009-12-04 09:08:41,931 INFO [org.springframework.batch.core.launch.support.SimpleJobLauncher] - <No TaskExecutor has been set, defaulting to synchronous executor.>
                2009-12-04 09:08:42,071 INFO [org.springframework.batch.core.launch.support.SimpleJobLauncher] - <Job: [FlowJob: [name=SFDC_OP_UPD_00]] launched with the following parameters: [{}]>
                2009-12-04 09:08:42,071 DEBUG [org.springframework.batch.core.job.AbstractJob] - <Job execution starting: JobExecution: id=0, startTime=null, endTime=null, lastUpdated=Fri Dec 04 09:08:42 EST 2009, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=0, JobParameters=[{}], Job=[SFDC_OP_UPD_00]]>
                2009-12-04 09:08:42,087 DEBUG [org.springframework.batch.core.job.flow.support.SimpleFlow] - <Resuming state=readLogTableData11 with status=UNKNOWN>
                2009-12-04 09:08:42,087 DEBUG [org.springframework.batch.core.job.flow.support.SimpleFlow] - <Handling state=readLogTableData11>
                2009-12-04 09:08:42,087 INFO [org.springframework.batch.core.job.AbstractJob] - <Executing step: [TaskletStep: [name=readLogTableData11]]>
                2009-12-04 09:08:42,087 DEBUG [org.springframework.batch.core.step.AbstractStep] - <Executing: id=0>
                2009-12-04 09:08:42,212 ERROR [org.springframework.batch.core.step.AbstractStep] - <Encountered an error executing the step>
                org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
                	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139)
                	at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:98)
                	at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:379)
                	at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
                	at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:348)
                	at org.springframework.batch.core.job.flow.FlowJob.access$0(FlowJob.java:1)
                	at org.springframework.batch.core.job.flow.FlowJob$JobFlowExecutor.executeStep(FlowJob.java:135)
                	at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
                	at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:144)
                	at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:124)
                	at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:103)
                	at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:250)
                	at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:110)
                	at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49)
                	at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:105)
                	at org.springframework.sample.batch.example.ExampleJobConfigurationTests.testLaunchJob(ExampleJobConfigurationTests.java:50)
                	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
                	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
                	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
                	at java.lang.reflect.Method.invoke(Method.java:597)
                	at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:160)
                	at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233)
                	at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333)
                	at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
                	at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
                	at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
                	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:160)
                	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
                	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
                	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
                	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
                	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
                	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
                	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
                	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
                	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
                	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
                	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
                	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
                Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [ftp://abc:abc@abc:21/apps/eaidbg1/spring_apps/Archive/External/PRDReport.csv]
                	at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245)
                	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:137)
                	... 38 more

                Comment


                • #9
                  So the error message says "Input resource must exist". Does it exist? Are your login credentials correct?

                  Comment


                  • #10
                    Yes.

                    If copy paste the same URL in "Internet Explorer Browser" I am able to download the file. Also, I have tried using apache FTP client API, that works fine too in reading the file part.

                    Regards,
                    Rama

                    Comment


                    • #11
                      @SpringBatchGuy,

                      I just found a random public FTP file and unit tested the "FlatFileItemReader" with:


                      Code:
                          reader.setResource(new UrlResource( new URL("ftp://barbes.polytechnique.fr/pub/Kalifa/LinuxCom.htm" )));
                      it worked (read the file successfully).

                      Just:

                      Code:
                      <beans:bean id="resource" class="org.springframework.core.io.UrlResource">
                      <beans:constructor-arg value="ftp://abc:abc@abc:21/apps/eaidbg1/spring_apps/Archive/External/PRDReport.csv"/>
                      </beans:bean>
                      won't work - you have to create a URL first, and then pass it to URLResource constructor:

                      Code:
                      new UrlResource( new URL("ftp://barbes.polytechnique.fr/pub/Kalifa/LinuxCom.htm" ))

                      Comment


                      • #12
                        I take it back:

                        Code:
                        reader.setResource(new UrlResource( "ftp://barbes.polytechnique.fr/pub/Kalifa/Emacs/emacs-faq.sgml" ));
                        works as well.

                        Comment


                        • #13
                          I bet this works too:

                          Code:
                          <bean id="writer" class="...FlatFileItemWriter">
                             <property name="resource" value="ftp://barbes.polytechnique.fr/pub/Kalifa/Emacs/emacs-faq.sgml"/>
                             ...
                          </bean>

                          Comment


                          • #14
                            Just checked with "spring-batch-samples", it does work indeed:

                            Code:
                            	<bean id="playerFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader">
                            		<property name="resource" value="ftp://barbes.polytechnique.fr/pub/Kalifa/Emacs/emacs-faq.sgml" />
                                            ...
                                     </bean>
                            niiice

                            Comment


                            • #15
                              Hi Litius/Dave,

                              Thanks for your help!!

                              But I am getting same exception. I don't know what I am doing wrong here.

                              Code:
                              Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): URL [ftp://abc:abc@abc:21/apps/eaidbg1/spring_apps/Archive/External/PRDReport.csv]
                              	at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245)
                              	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:137)
                              Any Idea why I am getting "reader is in 'strict' mode)" exception?

                              Thanks in advance.

                              Comment

                              Working...
                              X