Hi

Super. That works!!!

-----Original Message-----
From: Claus Ibsen <claus.ib...@gmail.com> 
Sent: Monday, March 7, 2022 6:03 PM
To: users@camel.apache.org
Subject: Re: Camel fails to rename/delete the source file

Hi

Yes it depends what smooks does, but you can change the message body from a 
file / input stream and read it into memory as a string and then give that to 
smooks.
Then smooks dont have anything to worry about closing file handles / resources

So try add before the processor

.convertBodyTo(String.class)


On Mon, Mar 7, 2022 at 10:40 AM Reto Peter <reto.pe...@advanceit.ch> wrote:
>
> Hi Claus
>
> Thanks for the fast answer!
> Well, this is the smooks processor, not my custom processor.
> Does that mean, the Camel file component does give the file access to the 
> next component and not just the file content?
> Sorry, I am a Camel beginner.
>
> Regards Reto
>
> -----Original Message-----
> From: Claus Ibsen <claus.ib...@gmail.com>
> Sent: Monday, March 7, 2022 4:41 PM
> To: users@camel.apache.org
> Subject: Re: Camel fails to rename/delete the source file
>
> Hi
>
> That is because you do something in the custom processor that locks the file.
> You need to make sure you close the file / input stream etc that you may be 
> doing.
>
> On Mon, Mar 7, 2022 at 9:14 AM Reto Peter <reto.pe...@advanceit.ch> wrote:
> >
> > I am trying to convert an EDIFACT file into an XML file.
> >
> > The conversion is done with smooks. The conversion works fine. The target 
> > file is successfully converted and also written to the disk.
> >
> > The problem arises after when Camel try to move the file to the .camel 
> > subdir.
> >
> > The source file is copied to the subdir, but the original file cannot be 
> > deleted.
> >
> >
> >
> > Environment: Windows 10, Java 11, Camel 3.15, Smooks 2.0.0RC1, 
> > running in eclipse
> >
> > If I omit the line with “.process(processor)”, the file can be 
> > moved/deleted. But with executing the smooks step it always gives me 
> > error messages, (attached at the end of this post)
> >
> >
> >
> > Following code shows the main program:
> >
> >        public static void main(String[] args) throws Exception {
> >
> >               CamelContext context = new DefaultCamelContext();
> >
> >               context.addRoutes(new RouteBuilder() {
> >
> >
> >
> >                      @Override
> >
> >                      public void configure() throws Exception {
> >
> >
> >
> >                            Smooks smooks = new Smooks();
> >
> >                            smooks.setReaderConfig(new 
> > EdifactReaderConfigurator("/d01b/EDIFACT-Messages.dfdl.xsd"));
> >
> >                            smooks.setExports(new 
> > Exports(StringResult.class));
> >
> >                            SmooksProcessor processor = new 
> > SmooksProcessor(smooks, context);
> >
> >
> >
> >
> > from("file://C:/data/MediaMarkt/ORDERS/in?delay=1000")
> >
> >                                   .process(processor)
> >
> >
> > .to("file://C:/data/MediaMarkt/ORDERS/out/?fileName=${file:name}.xml
> > ")
> > ;
> >
> >                     }
> >
> >
> >
> >              });
> >
> >              context.start();
> >
> >              Thread.sleep(20000);
> >
> >              context.close();
> >
> >
> >
> >        }
> >
> >
> >
> > Error message:
> >
> > [                          main] Scanner                        WARN  Not 
> > scanning classpath for ClassLoader 
> > 'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must 
> > implement 'java.net.URLClassLoader'.
> >
> > [                          main] Scanner                        WARN  Not 
> > scanning classpath for ClassLoader 
> > 'jdk.internal.loader.ClassLoaders$AppClassLoader'.  ClassLoader must 
> > implement 'java.net.URLClassLoader'.
> >
> > [                          main] SmooksProcessor                WARN  
> > Attachments module could not be found: attachments will not be propagated
> >
> > [                          main] SmooksProcessor                INFO  
> > SmooksProcessor [configUri=null] Started
> >
> > [                          main] SmooksProcessor                WARN  
> > Attachments module could not be found: attachments will not be propagated
> >
> > [                          main] SmooksProcessor                INFO  
> > SmooksProcessor [configUri=null] Started
> >
> > [                          main] SmooksProcessor                WARN  
> > Attachments module could not be found: attachments will not be propagated
> >
> > [                          main] SmooksProcessor                INFO  
> > SmooksProcessor [configUri=null] Started
> >
> > [                          main] SmooksProcessor                WARN  
> > Attachments module could not be found: attachments will not be propagated
> >
> > [                          main] SmooksProcessor                INFO  
> > SmooksProcessor [configUri=null] Started
> >
> > [                          main] SmooksProcessor                WARN  
> > Attachments module could not be found: attachments will not be propagated
> >
> > [                          main] SmooksProcessor                INFO  
> > SmooksProcessor [configUri=null] Started
> >
> > [                          main] AbstractCamelContext           INFO  
> > Routes startup (total:1 started:1)
> >
> > [                          main] AbstractCamelContext           INFO      
> > Started route1 (file://C:/data/MediaMarkt/ORDERS/in)
> >
> > [                          main] AbstractCamelContext           INFO  
> > Apache Camel 3.15.0 (camel-1) started in 193ms (build:36ms init:136ms 
> > start:21ms)
> >
> > CamelContext status: Started
> >
> > [//C:/data/MediaMarkt/ORDERS/in] DataProcessorFactory           INFO  
> > Compiling and caching DFDL schema...
> >
> > [//C:/data/MediaMarkt/ORDERS/in] GenericFileOnCompletion        WARN  Error 
> > during commit. Exchange[0C5E19CEB8FC187-0000000000000000]. Caused by: 
> > [org.apache.camel.component.file.GenericFileOperationFailedException - 
> > Error renaming file from C:\data\MediaMarkt\ORDERS\in\ORDERS 
> > 000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi to 
> > C:\data\MediaMarkt\ORDERS\in\.camel\ORDERS 
> > 000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi]
> >
> > org.apache.camel.component.file.GenericFileOperationFailedException:
> > Error renaming file from C:\data\MediaMarkt\ORDERS\in\ORDERS
> > 000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi 
> > to C:\data\MediaMarkt\ORDERS\in\.camel\ORDERS
> > 000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi
> >
> >        at
> > org.apache.camel.component.file.FileOperations.renameFile(FileOperat
> > io
> > ns.java:93) ~[camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.strategy.GenericFileProcessStrategyS
> > up
> > port.renameFile(GenericFileProcessStrategySupport.java:145)
> > ~[camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.strategy.GenericFileRenameProcessStr
> > at
> > egy.commit(GenericFileRenameProcessStrategy.java:121)
> > ~[camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.GenericFileOnCompletion.processStrat
> > eg
> > yCommit(GenericFileOnCompletion.java:134)
> > [camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.GenericFileOnCompletion.onCompletion
> > (G
> > enericFileOnCompletion.java:86) [camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.GenericFileOnCompletion.onComplete(G
> > en
> > ericFileOnCompletion.java:60) [camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.support.UnitOfWorkHelper.doneSynchronization(UnitOf
> > Wo
> > rkHelper.java:104) [camel-support-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.support.UnitOfWorkHelper.doneSynchronizations(UnitO
> > fW
> > orkHelper.java:93) [camel-support-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.impl.engine.DefaultUnitOfWork.done(DefaultUnitOfWork.
> > java:238) [camel-base-engine-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.support.UnitOfWorkHelper.doneUow(UnitOfWorkHelper.j
> > av
> > a:61) [camel-support-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.impl.engine.CamelInternalProcessor$UnitOfWorkProces
> > so
> > rAdvice.after(CamelInternalProcessor.java:778)
> > [camel-base-engine-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.impl.engine.CamelInternalProcessor$UnitOfWorkProces
> > so
> > rAdvice.after(CamelInternalProcessor.java:713)
> > [camel-base-engine-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.impl.engine.CamelInternalProcessor$AsyncAfterTask.d
> > on
> > e(CamelInternalProcessor.java:264)
> > [camel-base-engine-3.15.0.jar:3.15.0]
> >
> >        at org.apache.camel.AsyncCallback.run(AsyncCallback.java:44)
> > [camel-api-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule
> > (D
> > efaultReactiveExecutor.java:187) 
> > [camel-base-engine-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(De
> > fa
> > ultReactiveExecutor.java:64) [camel-base-engine-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.processor.Pipeline.process(Pipeline.java:184)
> > [camel-core-processor-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInt
> > er
> > nalProcessor.java:399) [camel-base-engine-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.GenericFileConsumer.processExchange(
> > Ge
> > nericFileConsumer.java:492) [camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.GenericFileConsumer.processBatch(Gen
> > er
> > icFileConsumer.java:245) [camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.GenericFileConsumer.poll(GenericFile
> > Co
> > nsumer.java:206) [camel-file-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.support.ScheduledPollConsumer.doRun(ScheduledPollCo
> > ns
> > umer.java:202) [camel-support-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.support.ScheduledPollConsumer.run(ScheduledPollCons
> > um
> > er.java:116) [camel-support-3.15.0.jar:3.15.0]
> >
> >        at
> > java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:5
> > 15
> > ) [?:?]
> >
> >        at
> > java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) 
> > [?:?]
> >
> >        at
> > java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask
> > .r
> > un(ScheduledThreadPoolExecutor.java:305) [?:?]
> >
> >        at
> > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor
> > .j
> > ava:1130) [?:?]
> >
> >        at
> > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.
> > java:630) [?:?]
> >
> >        at java.lang.Thread.run(Thread.java:832) [?:?]
> >
> > Caused by: java.io.IOException: Renaming file from 
> > 'C:\data\MediaMarkt\ORDERS\in\ORDERS
> > 000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi' 
> > to 'C:\data\MediaMarkt\ORDERS\in\.camel\ORDERS
> > 000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi'
> > failed: Cannot delete file 'C:\data\MediaMarkt\ORDERS\in\ORDERS
> > 000397700717-000397700717.2802b732-98b2-11ec-99b2-8e02ac1b4884.edi'
> > after copy succeeded
> >
> >        at
> > org.apache.camel.util.FileUtil.renameFileUsingCopy(FileUtil.java:464
> > )
> > ~[camel-util-3.15.0.jar:3.15.0]
> >
> >        at 
> > org.apache.camel.util.FileUtil.renameFile(FileUtil.java:436)
> > ~[camel-util-3.15.0.jar:3.15.0]
> >
> >        at
> > org.apache.camel.component.file.FileOperations.renameFile(FileOperat
> > io
> > ns.java:90) ~[camel-file-3.15.0.jar:3.15.0]
> >
> >        ... 28 more
> >
> >
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Reply via email to