Search code examples
regexmulemule-studiomule-el

How to route in Mule based on Incomming File Name


I have a requirement in mule to route based on file name ... I have a file endpoint where files will be placed and based on file name it will route to different flow ... my flow is :-

<flow name="Db1Flow3" doc:name="Db1Flow3" initialState="started">
    <file:inbound-endpoint responseTimeout="10000" connector-ref="File_Input" doc:name="File"  path="E:\backup\test">
        <file:filename-regex-filter pattern="SoapRequestInsert.xml,SoapRequestUpdate.xml,SoapRequestRetrieve.xml"   caseSensitive="false"/>
    </file:inbound-endpoint>

    <set-property propertyName="QuerySelect" value="${QuerySelect}" doc:name="To_Set_Query_In_Property_File"/>

    <choice doc:name="Choice">
        <when expression="#[message.outboundProperties['QuerySelect'] contains 'insert'] &amp;&amp; #[message.inboundProperties['originalFilename'].contains('SoapRequestInsert.xml')]">
            //Do something ....
        </when>
        <when expression="#[message.outboundProperties['QuerySelect'] contains 'update'] &amp;&amp; #[message.inboundProperties['originalFilename'].contains('SoapRequestUpdate.xml')]">
            //Do something other
        </when>
        <when expression="#[message.outboundProperties['QuerySelect'] contains 'select'] &amp;&amp; #[message.inboundProperties['originalFilename'].contains('SoapRequestRetrieve.xml')]">

            //Do something
        </when>
        <otherwise>
            //Do default            
        </otherwise>
    </choice>
</flow>

Now when ever I am placing a file in the input folder I am getting following exception :-

[Error: unbalanced braces]
[Near : {... '] contains 'insert'] && #[message.inboundProperti ....}]
[Line: 1, Column: 60] (org.mule.api.expression.InvalidExpressionException). Message payload is of type: ReceiverFileInputStream
Code   

           : MULE_ERROR--2

Please Help let me know if the MEL is correct to route based on input file name


Solution

  • Try this:

    <when expression="#[(message.outboundProperties['QuerySelect']).contains('insert') &amp;&amp; (message.inboundProperties['originalFilename']).contains('SoapRequestInsert.xml')]">
    
    //Do something ....
    
     </when>