Java 检查基于内容的路由是否存在文件

Java 检查基于内容的路由是否存在文件,java,apache-camel,predicate,Java,Apache Camel,Predicate,在一个camel路由器中,我们检查标志文件是否存在,并且仅当它存在时才继续。下面是我们打算使用的代码,但它不起作用 String flagFilePath = "file:" + flagFileFolder + "?noop=true&idempotent=false&fileName=" + flagFileName; from(flagFilePath) .choice() .when(header("CamelFil

在一个camel路由器中,我们检查标志文件是否存在,并且仅当它存在时才继续。下面是我们打算使用的代码,但它不起作用

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.");
我知道这里无法访问
否则
,因为如果文件不存在,则不会触发整个路由器

有没有一种简单的方法可以检查文件是否存在,而不用手工编写谓词


(注意:正如您在上面的代码中所看到的,我需要这个条件来触发警告日志。)

我将重新发布@ClausIbsen的评论作为答案。声誉应该都归@ClausIbsen所有

sendEmptyMessageWhenIdle=true
添加到文件URI可以解决我的问题

但是,我决定在代码中使用
谓词

    from("timer://a-processor?period=" + timerPeriod)
        .routeId("ATimer")
        .choice()
        .when(exchange -> Files.exists(Paths.get(flagFileFolder, flagFileName)))
            .log(LoggingLevel.DEBUG, "Flag file exists.")
        .otherwise()
            .log(LoggingLevel.DEBUG, "Flag file does not exist.")
        .end();

在我的例子中,我发现它更具可读性,语义更清晰。

是否应该将标志检查放在要调用的路由之外,然后在标志文件存在时调用路由?请参阅SendEmptyMessageWhenIdoption@ClausIbsen,谢谢,这解决了我的问题。在这种情况下是否需要
.endChoice()