1 Reply Latest reply on Aug 12, 2013 1:32 AM by Freeman(Yue) Fang

    Stream does not close

    Lalit Manchanda Newbie

      Hi

       

      I am using jboss-fuse-6.0.0.redhat-024 on Windows 7.

       

      The requirement is that I want to get the file headers, take some decision in a bean and then read record from the file one at a time

       

      I have created the following route, seems the stream is opening the file again but does not close when there are no more records to process and I don't have any other mechanism to close. Hence the following error comes, is it expected to behave this way? or do I have any option which I am missing?

       

      <route id="recon-route">

                           <from uri="file://{{recon.folder}}?recursive=true"/>

                       <bean ref="helloBean" method="readFromStream"/>

          </route>

       

       

      Source for readFromStream is as follows:

       

      public void readFromStream(Exchange exchange,@Body Object body,@Headers HashMap<String,Object> headers)

                {

                          String streamOutput = null;

                          ConsumerTemplate consumer =null;

                          String fileParentAbsolutePath=null;

                          String fileName=null;

                          String streamFilePath = null;

                          String streamUri = "stream:file?fileName=";

                          int beginIndex=0;

       

                          consumer = exchange.getContext().createConsumerTemplate();

       

                          //Assuming that camel - file headers will be set for file related items

       

                          streamFilePath = (String)headers.get("CamelFilePath");

       

                          streamUri=streamUri.concat(streamFilePath);

       

       

                          fileName=(String)headers.get("CamelFileName");

                          beginIndex=((String)headers.get("CamelFileAbsolutePath")).lastIndexOf(fileName);

                          fileParentAbsolutePath=          ((String)headers.get("CamelFileAbsolutePath")).substring(0,beginIndex-2);

       

                          //Read recon configuration to know which partnerIDs will have recon data coming in this file

       

                          do{

                          //streamOutput=consumer.receiveBody("stream:file?fileName=ftpOutput/CustomerDumpReport_Primary_20130720001528.CSV", String.class);

       

                          streamOutput=consumer.receiveBody(streamUri, 5000,String.class);

                          }while(streamOutput != null);

                          System.out.println(streamOutput);

                }

       

       

       

      I get the following exception when file component tries to move the file post processing:

       

      enericFileOperationFailedException - Error renaming file from D:\Other\Software\jboss-fuse-6.0.0.redhat-024\ftpOutput\sample\CustomerDumpReport_Primary_20130720001528.CSV to D:\Other\Software\jboss-fuse-6.0.0.redhat-024\ftpOutput\sample\.camel\CustomerDumpReport_Primary_20130720001528.CSV]

      org.apache.camel.component.file.GenericFileOperationFailedException: Error renaming file from D:\Other\Software\jboss-fuse-6.0.0.redhat-024\ftpOutput\sample\CustomerDumpReport_Primary_20130720001528.CSV to D:\Other\Software\jboss-fuse-6.0.0.redhat-024\ftpOutput\sample\.camel\CustomerDumpReport_Primary_20130720001528.CSV

              at org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:72)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.strategy.GenericFileProcessStrategySupport.renameFile(GenericFileProcessStrategySupport.java:107)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.strategy.GenericFileRenameProcessStrategy.commit(GenericFileRenameProcessStrategy.java:86)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.GenericFileOnCompletion.processStrategyCommit(GenericFileOnCompletion.java:134)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.GenericFileOnCompletion.onCompletion(GenericFileOnCompletion.java:82)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.GenericFileOnCompletion.onComplete(GenericFileOnCompletion.java:53)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.util.UnitOfWorkHelper.doneSynchronizations(UnitOfWorkHelper.java:55)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.impl.DefaultUnitOfWork.done(DefaultUnitOfWork.java:226)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.UnitOfWorkProcessor.doneUow(UnitOfWorkProcessor.java:199)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.UnitOfWorkProcessor.access$000(UnitOfWorkProcessor.java:37)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.UnitOfWorkProcessor$1.done(UnitOfWorkProcessor.java:157)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.RouteContextProcessor$1.done(RouteContextProcessor.java:56)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.Pipeline.process(Pipeline.java:106)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:46)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWorkProcessor.java:150)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:117)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNext(RouteInflightRepositoryProcessor.java:48)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:73)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:336)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:189)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:155)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:142)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:92)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:439)[:1.6.0_43]

              at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)[:1.6.0_43]

              at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)[:1.6.0_43]

              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)[:1.6.0_43]

              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:180)[:1.6.0_43]

              at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:204)[:1.6.0_43]

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)[:1.6.0_43]

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)[:1.6.0_43]

              at java.lang.Thread.run(Thread.java:662)[:1.6.0_43]

      Caused by: java.io.IOException: Renaming file from: D:\Other\Software\jboss-fuse-6.0.0.redhat-024\ftpOutput\sample\CustomerDumpReport_Primary_20130720001528.CSV to: D:\Other\Software\jboss-fuse-6.0.0.redhat-024\ftpOutput\sample\.camel\CustomerDumpReport_Primary_20130720001528.CSV failed due cannot delete from file: D:\Other\Software\jboss-fuse-6.0.0.redhat-024\ftpOutput\sample\CustomerDumpReport_Primary_20130720001528.CSV after copy succeeded

              at org.apache.camel.util.FileUtil.renameFile(FileUtil.java:528)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              at org.apache.camel.component.file.FileOperations.renameFile(FileOperations.java:70)[130:org.apache.camel.camel-core:2.10.0.redhat-60024]

              ... 36 more

       

       

       

      Thanks

      Lalit