Forum Home » Fuse Distributions » Fuse Mediation Router

Thread: Unable to get moveFailed to work for File2 component

 

Permlink Replies: 7 - Last Post: Apr 26, 2012 8:05 AM Last Post By: davsclaus
mohithanda

Posts: 13
Registered: 11/28/11
Unable to get moveFailed to work for File2 component
Posted: Apr 24, 2012 7:22 AM
  Click to reply to this thread Reply
Hi Guys,

I had a look at the documentation on http://camel.apache.org/file2.html

I tried the following endpoints to consume files

file:C:\\temp
csv?move=done&moveFailed=error/{file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}

file:C:\\temp\\csv?move=done&moveFailed=error\{file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}

And I get the following error

Cannot create directory: C:\temp\csv\error{file:name.noext}-now:yyyyMMddHHmmssSSS.ext (could be because of denied permissions)

Now the interesting thing is, if I use just file:C:\\temp
csv?move=done&moveFailed=error, it creates error directory and puts the source file into the error directory.

So, I am not sure why I am getting permission denied issues. Also, not sure why the errors says Can not create directory, I am just sending file to an existing directory. Because error directory was created when I used file:C:\\temp
csv?move=done&moveFailed=error

Please advise.

Regards,
Mohit
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Unable to get moveFailed to work for File2 component
Posted: Apr 24, 2012 7:25 AM   in response to: mohithanda in response to: mohithanda
  Click to reply to this thread Reply
There is a missing $ in the {file:name.noext}. When you use those { } tokens, then the first should always be ${ and the closing a }.
mohithanda

Posts: 13
Registered: 11/28/11
Re: Unable to get moveFailed to work for File2 component
Posted: Apr 24, 2012 7:47 AM   in response to: davsclaus in response to: davsclaus
  Click to reply to this thread Reply
Thanks Claus for the prompt response.

Now my endpoint looks like the following

file:C:\\temp\\csv?move=done&moveFailed=error
${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}

I also tried

file:C:\\temp
csv?move=done&moveFailed=error/${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}

Just tried that and I get the following error

Caused by: org.apache.camel.component.file.GenericFileOperationFailedException - Cannot create directory: C:\temp\csv\error\name.noext-now:yyyyMMddHHmmssSSS.ext (could be because of denied permissions)

My input filename is test_with_headers-error.csv

Do I have to set something in the exchange message header?

Regards,
Mohit
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Unable to get moveFailed to work for File2 component
Posted: Apr 24, 2012 12:04 PM   in response to: mohithanda in response to: mohithanda
  Click to reply to this thread Reply
What version of Camel are you using?

And if you use XML, then make sure to use & as the &, because with XML you must escape the & chars.
mohithanda

Posts: 13
Registered: 11/28/11
Re: Unable to get moveFailed to work for File2 component
Posted: Apr 25, 2012 12:23 AM   in response to: davsclaus in response to: davsclaus
  Click to reply to this thread Reply
I am using camel 2.6.0

I am also using DSL to define my routes. Although I am injecting the file endpoint using spring config into my RouteBuilder class. And the spring config uses PropertyPlaceHolder and reads a .properties file to lookup the endpoint definition.

.properties file

test.source.file.or.directory=file:C:\\temp\\csv?move=done&moveFailed=error
${file:name.noext}-${date:now:yyyyMMddHHmmssSSS}.${file:ext}

Spring config snippet
<bean id="testtRouteBuilder"
class="com.mycompany.servicebus.services.test.routes.TestRouteBuilder">
<property name="source" value="${test.source.file.or.directory}" />

Edited by: mohithanda on Apr 25, 2012 12:24 AM
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Unable to get moveFailed to work for File2 component
Posted: Apr 25, 2012 5:03 AM   in response to: mohithanda in response to: mohithanda
  Click to reply to this thread Reply
Can you try a newer version of Camel. There used to be a bug in an older release about the ${ } not working on the file component.
mohithanda

Posts: 13
Registered: 11/28/11
Re: Unable to get moveFailed to work for File2 component
Posted: Apr 25, 2012 11:41 PM   in response to: davsclaus in response to: davsclaus
  Click to reply to this thread Reply
Ok. I can try that.

In the meantime, I printed out the source endpoint in my route builder and I see the following

file:C:\temp\csv?move=done&moveFailed=error\name.noext-now:yyyyMMddHHmmssSSS.ext

Seems like something is stripping out all the placeholders in the endpoint definition. As in, ${} doesn't get printed. Not sure if this is the expected behaviour or not.

from(getSource())
.process(new Processor() {

@Override
public void process(Exchange exchng) throws Exception {
LOGGER.debug(":" + getSource() + ":");
}
})

And I see

:file:C:\temp\csv?move=done&moveFailed=error\name.noext-now:yyyyMMddHHmmssSSS.ext:

Edited by: mohithanda on Apr 25, 2012 11:48 PM
davsclaus

Posts: 1,893
Registered: 10/14/08
Re: Unable to get moveFailed to work for File2 component
Posted: Apr 26, 2012 8:05 AM   in response to: mohithanda in response to: mohithanda
  Click to reply to this thread Reply
How do you use and run your application? Do you use Spring? And if so do you use spring property placeholders or some sort?

Yes the ${ } should be preserved, but Camel will normalize the uri, so some tokens gets printed as %2F etc using an encoded value.