camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From JKemp <>
Subject Re: File Exists
Date Fri, 31 Jan 2014 19:47:11 GMT
Ah, whoops, my fault.  I was looking at the File documentation and not at

I think I have a working solution, but I'm wondering if I'm going about this
in the best way.

I set up my route with the filter:

	<bean id="bothFilesReceivedFilter"
class="com.mycompany.BothFilesReceivedFilter" />

	<camelContext xmlns="">
		<route id="report-file-consolidation">
			<split streaming="true">
				<tokenize includeTokens="true" token="\n" group="5000" />
				<convertBodyTo type="String" charset="UTF-8" />
				<setHeader headerName="CamelFileName">
                <to uri="log:lineparser?showBody=true&amp;showHeaders=true"
				<to uri="file:///data/output?fileExist=Append" />

And I set my filter up like this:

public class BothFilesReceivedFilter<T> implements GenericFileFilter<T> {
	Logger log = Logger.getLogger();
	HashSet<String> namesReceived = new HashSet<String>();
	public boolean accept(GenericFile<T> file) {
		log.debug("Received file named: " + file.getFileName());
		if (file.getFileName().equals("foo.txt")){
			return namesReceived.contains("bar.txt");
		else if (file.getFileName().equals("bar.txt")){
			return namesReceived.contains("foo.txt");
		else {
			return false;

And this seems to work.  Is this sort of what you guys meant?  The only
thing I don't really like about this solution is that the file filtering
still seem to be getting evaluated separately from each other.  So with the
above solution, after both files have been received, if we receive another
input file with the same name, it gets processed immediately even when there
isn't the companion file in the input directory as well, because the HashSet
still shows that both files have been received.  But if I clear out the Set
once both files have been received, I think it will ignore the second file.

Since I was using maxMessagesPerPoll, I thought this would work as a batch
consumer, but I don't see the CamelBatchSize header populated when I print
the headers.  Is there any way to make the filtering inspect all the files
in the batch at once?

Am I off track here?

Thanks again.

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message