views:

290

answers:

2

I have camel Fileendpoint defined in following way:

<bean id="hotfolderEndpoint" 
          class="org.apache.camel.component.file.FileEndpoint"
          factory-bean="camel" 
          factory-method="getEndpoint">       
        <constructor-arg ref="hotfolder" />
</bean>

I want to define some File parameters such as preMove, move etc. Variable hotfolder is String taken from JNDI and I have no impact on it. When I define property as

<bean id="moveExp" class="org.apache.camel.model.language.SimpleExpression">
 <property name="expression" value="done/${file:name}"/>
</bean>

it is not correctly parsed and the file get name done/name

A: 

preMove is an option on FileEndpoint so you can just let spring IoC it

<bean>
    <property name="preMove" value="done"/>
</bean>

And I believe that you can omit ${file:name} if you just want it moved to a folder. Its already documented at the Camel wiki page http://camel.apache.org/file2.html

BTW: What version of Camel are you using and which OS?

Claus Ibsen
I'm using Camel 2.2 on Windows XP SP3. Suggested solution wont work because preMove given as String value can not be casted to Expression and thus result in Exception.
sempa
+1  A: 

I Case

<camel:camelContext id="camel">
                <camel:route>
                        <camel:from ref="hotfolderEndpoint"/>
                        <camel:to uri="file://c:/test/myfolder/toEnd"></camel:to>
                </camel:route>
        </camel:camelContext>

        <camel:endpoint id="hotfolderEndpoint" camelContextId="camel"
                uri="file://c:/test/hotfolder?move=backup/${date:now:yyyyMMdd}/${file:name}"/>

Result: org.apache.camel.component.file.GenericFileOperationFailedException: Cannot create directory: c:\test\hotfolder\backup\now:yyyyMMdd\name

II Case DSL

from("file://c:/test/myfolder?preMove=inprogress&moveFailed=backup/${date:now:yyyyMMdd}/${file:name}")
                .to("file://c:/test/myfolder/toEnd");

Result preMove works fine (inprogress folder created), but move throws exception: GenericFileOperationFailedException: Cannot rename file: GenericFile[c:\test\hotfolder\xxx.txt] to: GenericFile[backup\20100512]

III Case

<bean id="hotfolderEndpoint"
         class="org.apache.camel.component.file.FileEndpoint"
         factory-bean="camel"
         factory-method="getEndpoint">    
            <constructor-arg ref="hotfolder" />
            <property name="readLock" value="rename" />
            <property name="move" ref="moveExp"/>
    </bean>
    <bean id="moveExp" class="org.apache.camel.model.language.SimpleExpression">
            <property name="expression" value="done/${file:name.noext}-done.${file:ext}"/>
    </bean>

Simlar Problem to Case II

IV Case

<camel:camelContext id="camel">
                <camel:route>
                        <camel:from uri="file://c:/test/hotfolder?move=backup/${date:now:yyyyMMdd}/${file:name}"/>
                        <camel:to uri="file://c:/test/myfolder/toEnd"></camel:to>
                </camel:route>
        </camel:camelContext>

Result: work as expected

Question: Am I doing sth wrong or there is a bug in Camel

sempa