-
1. Re: Spring DSL <Choice> example
davsclaus Feb 10, 2009 2:55 AM (in response to mrichards_mrichards)<camel:simple>${in.header.file.name} == '.bar_m*'</camel:simple>
The simple language does not support operators such as == for comparison. Its very simple and only to be used for testing if a header exists, or to concat a string etc.
What you need to use instead is the xpath that supports = for comparison:
http://camel.apache.org/content-based-router.html
http://camel.apache.org/xpath.html
<camel:xpath>$org.apache.camel.file.name = '.bar_m*'</camel:simple>
But you want to test if the filename starts with bar_m, so you need to use the starts-with() xpath function. Try googling how to use it.
If xpath gets just fuzzed to work with, as many of the xml stuff, then you can try another language that is more java like where you can use .startsWith or .matches or what else methods exists.
http://camel.apache.org/el.html
http://camel.apache.org/ognl.html
Or you can use regular Java and implement the test in a plain java class = POJO. See the link below for a sample:
http://camel.apache.org/bean-language.html.
Edited by: davsclaus on Feb 10, 2009 7:54 AM
-
2. Re: Spring DSL <Choice> example
mrichards_mrichards Feb 10, 2009 10:05 AM (in response to davsclaus)Hey Claus,
Thanks for that. I'm working with flat files .csv's. I have to route them to different folders depending on what the file names begin with
I've tried using xpath inside my route
trial 1)
<camel:route>
<camel:from uri="file://C:/temp/inFiles?moveNamePrefix=&noop=true&" />
<camel:choice>
<camel:when>
<camel:xpath>$org.apache.camel.file.name='.aasd.xml'</camel:xpath>
<camel:to uri="file://C:/temp/outFiles/" />
</camel:when>
</camel:choice>
<camel:otherwise>
<camel:to uri="file://C:/temp/deadLetter?autoCreate=false" />
</camel:otherwise>
</camel:route>
trial 2)
<camel:route>
<camel:from uri="file://C:/temp/inFiles?moveNamePrefix=&noop=true&" />
<camel:choice>
<camel:when>
<camel:xpath>in.headers[$org.apache.camel.file.name] ='.*'</camel:xpath>
<camel:to uri="file://C:/temp/outFiles/" />
</camel:when>
</camel:choice>
<camel:otherwise>
<camel:to uri="file://C:/temp/deadLetter?autoCreate=false" />
</camel:otherwise>
</camel:route>
trial n)
..
..
<camel:xpath>$org.apache.camel.file.name='.a*'</camel:xpath>
..
...
trial n+1)
<camel:xpath>${org.apache.camel.file.name}[starts-with(${org.apache.camel.file.name},'.a')]</camel:xpath>
..
..
<camel:xpath>in.headers[$org.apache.camel.file.name][starts-with($org.apache.camel.file.name,'a')]</camel:xpath>
..
..
<camel:xpath>in:header[org.apache.camel.file.name][starts-with(org.apache.camel.file.name,'a')]</camel:xpath>
I've even tried writing it as a filter to check I can repeat the examples
<camel:route>
<camel:from uri="file://C:/temp/inFiles?moveNamePrefix=&noop=true&" />
<camel:filter>
<camel:xpath>$org.apache.camel.file.name = '.a*'</camel:xpath>
<camel:process ref="logger"/>
<camel:to uri="file://C:/temp/outFiles/" />
</camel:filter>
</camel:route>
All my files end up in the deadletter folder, which means the comparison isn't working or I get an InvalidXPathExpression: Invalid xpath as my xpath is wrong.
From within xpath,
Does $org.apache.camel.file.name give you the file name?
I've read over a few times http://camel.apache.org/xpath.html
and I should be able to access the file name from
message.in.header
I've managed to achieve setting the file name comparison from within the xml using my own bean, I've attched the xml and the pojo. I'd still love to know if it can be done using xpath
Yours hopingly
Cheers
Mark
-
spring.xml 2.5 KB
-
FileHeaderTester.java 628 bytes
-
-
3. Re: Spring DSL <Choice> example
davsclaus Feb 10, 2009 10:52 AM (in response to mrichards_mrichards)Hi
Does $org.apache.camel.file.name give you the file name?
The $ notation should be a shorthand to get the in headers. But since the header name itself has dots in it, it might confuse xpath. Have you tried with ' ' around
$'org.apache.camel.file.name'
I am not particual keen on xpath, to do non XML work. So personally I use one of the other scripting languages, or even better with POJO as I can unit test it in isolation.
You might wanna mess around with it for a while until the xpath stuff works. But I stay clear of it mostly and use other solutions.
In Java DSL you have expression builders so you can express it more powerful. We are considering how to bring that into the Spring XML as well.
-
4. Re: Spring DSL <Choice> example
mrichards_mrichards Feb 10, 2009 5:23 PM (in response to davsclaus)Hi Claus,
Yeah, I'll start looking more into some of the scripting languages. Writting my own bean was pretty simple so I'll go with that for the moment, while I build up camel knowledge and identify more scenarios where I can use Fuse/Camel.
Thanks for all help and quick responses,
Cheers
Mark