-
1. Re: Transform a file into a filename inside a route.
jradecki Oct 20, 2011 10:02 PM (in response to markk)Great spring; see explore <to uri stuff; easy; be patient...++1
-
2. Re: Transform a file into a filename inside a route.
davsclaus Oct 21, 2011 3:16 AM (in response to markk)Hi
Use the simple language instead of constant, and refer to the file as
http://camel.apache.org/simple.html
http://camel.apache.org/file-language.html
So basically something like
<simple>${file:name}</simple>
-
3. Re: Transform a file into a filename inside a route.
markk Oct 21, 2011 10:11 AM (in response to markk)Simple seems like the proper solution, but it doesn't seem like it is allowed inside route tags
<route> <from uri="file:inftp/?move=tagged/${file:name}"></from> <setBody> <simple>${file:name}</simple> </setBody> <to uri="activemq:queue:newFiles"></to> </route>
Throws an exception:
Element 'route' cannot have character children, because the type's content type is element-only.
Using a simple bean is fine, it would have been nice with only XML though.
<route> <from uri="file:inftp/?move=tagged/${file:name}"></from> <bean ref="myFileName" method="process"></bean> <to uri="activemq:queue:newFiles"></to> </route> <bean id="myFileName" class="com.foo.examples.camel_file.FileNameReplacer"></bean>
import org.apache.camel.Processor; import org.apache.camel.Exchange; public class FileNameReplacer implements Processor { public void process(Exchange exchange) throws Exception { exchange.getIn().setBody( exchange.getIn().getHeader("CamelFileName") ); } }
p.s. is there no way to format code in this forum?
yes, it is with curly brace code tags... not listed with the rest of the formatting, doesn't show up in preview, and doesn't follow square brackets like any of the other markup... nice ... oh, and the end code tag does not have a slash.
Edited by: markk on Oct 21, 2011 2:10 PM
-
4. Re: Transform a file into a filename inside a route.
davsclaus Oct 21, 2011 10:06 AM (in response to markk)Hm
You should be able to refer to a header as well
-
5. Re: Transform a file into a filename inside a route.
markk Oct 21, 2011 10:15 AM (in response to davsclaus)Yes, I think that's it!
<camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="file:inftp/?move=tagged/${file:name}"></from> <setBody> <simple>${header.CamelFileName}</simple> </setBody> <log message="The message contains ${body}"></log> <to uri="activemq:queue:newFiles"></to> </route> </camelContext>
I'm pretty sure it does not read the entire file body into the message either. If I remove the setBody tag, and put a 900 Meg .iso file into the "inftp/" directory, then the whole thing grinds to a halt. (which is a good thing). When I have that setBody in there, it is near instantaneous delivery to the queue.
Brilliant!
-
6. Re: Transform a file into a filename inside a route.
davsclaus Oct 23, 2011 3:23 AM (in response to markk)Yes you replace the message body with the file name, and thus the java.io.File handle for the actual file is no longer in the body, and therefore Camel does not load the 900mb when you log the message body in the log statement.