如何检查Mule esb中是否存在文件

Mar*_*zak 4 java esb mule

我想使用选择流控制,当名为#[function:dateStamp:dd-MM-yyyy] .xml的文件存在时,将选择一个路由,当此文件不存在时,将选择其他路由.

是否可以写'何时'选择部分来检查文件是否存在?

Dav*_*sot 9

您可以使用MEL:

<configuration>
    <expression-language>
        <import class="java.text.SimpleDateFormat" />
        <global-functions><![CDATA[
          def xmlFileExists() {
            filePath = '/tmp/' + new SimpleDateFormat('dd-MM-yyyy').format(new Date()) + '.xml';
            new File(filePath).isFile();
          }
        ]]></global-functions>
    </expression-language>
</configuration>

...

    <choice>
        <when expression="#[xmlFileExists()]">
            ...
        </when>
        <otherwise>
            ...
        </otherwise>
    </choice>
Run Code Online (Sandbox Code Playgroud)