Here's a patch for FileProducer.java that fixes the "directory being created
as file" issue.
protected File createFileName(Message message) {
File answer;
File endpointFile = endpoint.getFile();
String name = null;
if (!endpoint.isIgnoreFileNameHeader()) {
name = message.getHeader(FileComponent.HEADER_FILE_NAME,
String.class);
}
if (endpointFile.isDirectory()) {
if (name != null) {
answer = new File(endpointFile, name);
if (answer.isDirectory()) {
answer = new File(answer, message.getMessageId());
}
} else {
answer = new File(endpointFile, message.getMessageId());
}
} else {
if (name == null) {
answer = endpointFile;
} else {
answer = new File(endpointFile, name);
}
}
return answer;
}
After applying this patch, the unit tests passes every time.
However, I still do get exceptions in the log output. It looks like a
multi-threading issue. As you can see from the logs below, the
buildDirectory() for file9 is entered while buildDirectory() for file 0 is
still running
500 [main] DEBUG org.apache.camel.util.ProducerCache - >>>>
Endpoint[seda:testFileCreatedAsDir] Exchange[Message: Contents of test file]
540 [seda:file0 thread:1] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file0.txt)
540 [seda:file9 thread:10] DEBUG
org.apache.camel.component.file.FileProducer -
buildDirectory(a\b\c\d\e\f\g\h\file9.txt)
540 [seda:file0 thread:1] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file0.txt) finished
570 [seda:file0 thread:1] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file0.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
570 [seda:file0 thread:1] ERROR org.apache.camel.processor.DeadLetterChannel
- On delivery attempt: 0 caught: java.io.FileNotFoundException:
a\b\c\d\e\f\g\h\file0.txt (The system cannot find the path specified)
java.io.FileNotFoundException: a\b\c\d\e\f\g\h\file0.txt (The system cannot
find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:179)
at java.io.FileOutputStream.<init>(FileOutputStream.java:131)
at
org.apache.camel.component.file.FileProducer.process(FileProducer.java:84)
at
org.apache.camel.component.file.FileProducer.process(FileProducer.java:60)
at
org.apache.camel.impl.converter.AsyncProcessorTypeConverter$ProcessorToAsynProcessorBridge.process(AsyncProcessorTypeConverter.java:44)
at
org.apache.camel.processor.SendProcessor.process(SendProcessor.java:73)
at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:136)
at
org.apache.camel.processor.DeadLetterChannel.process(DeadLetterChannel.java:86)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:101)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:85)
at
org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProcessor.java:53)
at
org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:61)
at java.lang.Thread.run(Thread.java:595)
570 [seda:file0 thread:1] DEBUG org.apache.camel.processor.DeadLetterChannel
- Sleeping for: 1000 until attempting redelivery
580 [seda:file1 thread:2] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file1.txt)
580 [seda:file1 thread:2] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file1.txt) finished
580 [seda:file1 thread:2] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file1.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
590 [seda:file2 thread:3] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file2.txt)
590 [seda:file2 thread:3] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file2.txt) finished
590 [seda:file3 thread:4] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file3.txt)
590 [seda:file4 thread:5] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file4.txt)
590 [seda:file5 thread:6] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file5.txt)
590 [seda:file6 thread:7] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file6.txt)
590 [seda:file7 thread:8] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file7.txt)
590 [seda:file9 thread:10] DEBUG
org.apache.camel.component.file.FileProducer -
buildDirectory(a\b\c\d\e\f\g\h\file9.txt) finished
590 [seda:file8 thread:9] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file8.txt)
590 [seda:file2 thread:3] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file2.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
590 [seda:file3 thread:4] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file3.txt) finished
590 [seda:file4 thread:5] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file4.txt) finished
590 [seda:file5 thread:6] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file5.txt) finished
590 [seda:file6 thread:7] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file6.txt) finished
590 [seda:file7 thread:8] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file7.txt) finished
590 [seda:file9 thread:10] DEBUG
org.apache.camel.component.file.FileProducer - About to write to:
a\b\c\d\e\f\g\h\file9.txt from exchange: Exchange[FileMessage:
a\b\c\d\e\f\g\h]
590 [seda:file8 thread:9] DEBUG org.apache.camel.component.file.FileProducer
- buildDirectory(a\b\c\d\e\f\g\h\file8.txt) finished
590 [seda:file4 thread:5] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file4.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
590 [seda:file5 thread:6] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file5.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
590 [seda:file6 thread:7] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file6.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
590 [seda:file3 thread:4] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file3.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
590 [seda:file7 thread:8] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file7.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
600 [seda:file8 thread:9] DEBUG org.apache.camel.component.file.FileProducer
- About to write to: a\b\c\d\e\f\g\h\file8.txt from exchange:
Exchange[FileMessage: a\b\c\d\e\f\g\h]
1572 [seda:file0 thread:1] DEBUG
org.apache.camel.component.file.FileProducer -
buildDirectory(a\b\c\d\e\f\g\h\file0.txt)
1572 [seda:file0 thread:1] DEBUG
org.apache.camel.component.file.FileProducer -
buildDirectory(a\b\c\d\e\f\g\h\file0.txt) finished
1572 [seda:file0 thread:1] DEBUG
org.apache.camel.component.file.FileProducer - About to write to:
a\b\c\d\e\f\g\h\file0.txt from exchange: Exchange[FileMessage:
a\b\c\d\e\f\g\h]
--
View this message in context:
http://www.nabble.com/Problem-with-concurrent-dir-file-access--tf4724448s22882.html#a13543906
Sent from the Camel - Users mailing list archive at Nabble.com.