In one camel router, we are check if a flag file exists and only continue if it does. Here is the code we intend to use, but it does not work.
String flagFilePath = "file:" + flagFileFolder
+ "?noop=true&idempotent=false&fileName=" + flagFileName;
from(flagFilePath)
.choice()
.when(header("CamelFileName").isNotNull())
.log(LoggingLevel.TRACE, "Flag file exists.")
.otherwise()
.log(LoggingLevel.INFO, "Flag file does not exist.");
I understand that otherwise is not reachable here because the whole router is not triggered if the files does not exist.
Is there an easy way to check if the file exists without hand-writing Predicates?
(Note: As you can see in the code above, I need this condition to trigger a warning log.)
I am going to re-post @ClausIbsen's comments as an answer. The reputation should all go to @ClausIbsen.
Adding
sendEmptyMessageWhenIdle=trueto the file URI solves my problem.However, I decided to use a
Predicatein my code.I find it more readable and more clear in semantics in my case.