Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if file exists in Mule esb

Tags:

java

esb

mule

I want to use choice flow control which will chose one route when file named #[function:dateStamp:dd-MM-yyyy].xml exists and other route when this file does not exist.

Is it possible to write 'when' part of choice to check for file existence?

like image 311
Marcin Szymczak Avatar asked Dec 12 '22 12:12

Marcin Szymczak


1 Answers

You could use 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>
like image 125
David Dossot Avatar answered Dec 29 '22 00:12

David Dossot