Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Camel file component with dynamic path

I am trying to set dynamic path in camel file component to avoid platform specific paths. But camel is not allowing this as it doesn't expect $ in directory path.

What I am trying to do is to set a VM param say file.home and then use this into my file component like

file:\${file.home}\type1

This will allow me to eliminate the platform specific path directly. I tried externalizing this into property file but then Spring doesn't understand the camel specific dynamic language for e.g. ${in.header.abc}

Can someone help me out in achieving this.

like image 263
VGaur Avatar asked Jul 24 '26 16:07

VGaur


2 Answers

Those answers are not correct. If you use a BridgePropertyPlaceholderConfigurer and a PropertiesComponent, you can use dynamic values everywhere.

<bean id="bridgePropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
    <property name="properties">
        <value>
...normal property syntax name=value - use this in test definitions
        </value>
    </property>
</bean>

Or use something like this in real application

<bean id="dummyPropertyPlaceholder" class="org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer">
    <property name="location" value="classpath:/dummy.properties" />
</bean>

e.g.

    <route id="DummyRoute">
        <from uri="file:{{dummy.int.dir}}?delay={{poll.delay}}&amp;initialDelay={{initial.delay}}&amp;{{readlockChanged}}&amp;move={{root}}/{{dummy.arch.dir}}/{{archive.dir}}&amp;moveFailed={{error.dir}}&amp;scheduledExecutorService=#scheduledExecutorService" />
            <to uri="file:{{root}}/{{dummy.int.destination.dir}}" />
    </route>

There is a trick with later versions of Camel: use $simple{file.path} instead of ${file.path} so Spring won't strip your ${} and pass the bare file.path to Camel. E.g. a move on an input 'from' uri might be like this:

move=archive/$simple{date:now:yyyyMMdd}/$simple{file:name}

http://camel.apache.org/how-do-i-use-spring-property-placeholder-with-camel-xml.html

http://camel.apache.org/using-propertyplaceholder.html

like image 185
Alan Avatar answered Jul 28 '26 08:07

Alan


According to Camel File Component:

Camel supports only endpoints configured with a starting directory. So the directoryName must be a directory. If you want to consume a single file only, you can use the fileName option e.g., by setting fileName=thefilename. Also, the starting directory must not contain dynamic expressions with ${} placeholders. Again use the fileName option to specify the dynamic part of the filename.

So, you could do somethings like:

from(...).to("file://?fileName=${somePathAndSomeFile}").to(...)
like image 23
Joseph Hui Avatar answered Jul 28 '26 09:07

Joseph Hui