1

I am downloading files from FTP. I am able to download files with defined patterns or defined name and pass then process these files in Java.

Problem I am facing is that I need to download a new file every week. The file name is like "constant-prefix-2013-W51.zip". My current XML is like this;

<ftp:inbound-endpoint 
    host="${ftp.host}" 
    port="${ftp.port}" 
    path="${ftp.pathInbound}" 
    user="${ftp.user}" 
    password="${ftp.password}" 
    responseTimeout="10000" 
    doc:name="KBB_FTP" >

    <file:filename-wildcard-filter pattern="MyFile-2013-W51.zip"/>

</ftp:inbound-endpoint>

Flow Reference: Mule: How to pass File from FTP to Java class in Mule ESB?

This code downloads the requested file successfully. But I need to add the year and week value dynamically in file pattern.

I have tried following patterns but no success;

 1. pattern="MyFile-2013-W#[server.dateTime.weekOfYear].zip" 

 2. pattern="MyFile-2013-W${server.dateTime.weekOfYear}.zip"

I know second pattern is totally wrong as it is not a property which is defined in .properties file. I also added a property in mule-app.properties like this

 calendar.weekOfYear=#[server.dateTime.weekOfYear]

and used following pattern;

 3. pattern="MyFile-2013-W${calendar.weekOfYear}.zip"

None of this way is working, I want to add year value like 2013 and week value like 51 dynamically which is not happening in any case. Value which appends to fileName is only above string patterns, not any digit..

Community
  • 1
  • 1
Rizwan Sohaib
  • 1,240
  • 17
  • 27

2 Answers2

1

The file:filename-wildcard-filter does not support MEL expressions. Use an expression-filter instead, like this:

<message-filter throwOnUnaccepted="false">
    <expression-filter
        expression="#[message.outboundProperties.originalFilename == 'MyFile-2013-W'+server.dateTime.weekOfYear+'.zip']" />
</message-filter>
David Dossot
  • 33,403
  • 4
  • 38
  • 72
  • Can you plz explain little more with some code snippet as I am a newbie in mule.. my purpose is to get the file downloaded with a way that fulfills above mentioned requirements.. – Rizwan Sohaib Dec 23 '13 at 05:41
  • I have tried few expressions, but there are errors and exceptions being generated. It will be helpful if you can tell me a line of xml tag to be added in above code.. – Rizwan Sohaib Dec 23 '13 at 06:08
  • Sure, added an example. – David Dossot Dec 24 '13 at 01:20
  • I have replaced my line of code `` with your piece of code. But I am getting following error; >>>>> `[Error: could not access: originalFilename; in class: org.mule.el.context.MessagePropertyMapContext] [Near : {... message.inboundProperties.orig ....}]` – Rizwan Sohaib Dec 24 '13 at 07:50
  • 2. `Execution of the expression "message.inboundProperties.originalFilename == 'KBBUsedVehiclesNoSpecTabFormat-2013-W'+server.dateTime.weekOfYear+'.zip'" failed. (org.mule.api.expression.ExpressionRuntimeException) org.mule.el.mvel.MVELExpressionLanguage:213 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)` – Rizwan Sohaib Dec 24 '13 at 09:15
  • 3. `Execution of the expression "message.inboundProperties.originalFilename == 'KBBUsedVehiclesNoSpecTabFormat-2013-W'+server.dateTime.weekOfYear+'.zip'" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: byte[] (org.mule.api.MessagingException) org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html) ` – Rizwan Sohaib Dec 24 '13 at 09:16
  • In some transports the properties to be used in an inbound filter happen to be in the outbound scope: maybe it's the case with FTP. Therefore I have changed my answer to use the `outboundProperties` map. I can't test because I don't have an FTP server handy. – David Dossot Dec 24 '13 at 17:48
  • I already tried with outboundProperties, it does not work either. I saw ur answer from here about this; http://stackoverflow.com/questions/18881530/mule-originalfilename-is-null I am getting following Error if I use `outbountProperties`: `Message : Message has been rejected by filter. Message payload is of type: byte[] Code : MULE_ERROR--2` – Rizwan Sohaib Dec 25 '13 at 06:22
  • `Exception stack is: >>>>> 1. Message has been rejected by filter. Message payload is of type: byte[] (org.mule.api.routing.filter.FilterUnacceptedException) org.mule.routing.MessageFilter:100 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/routing/filter/FilterUnacceptedException.html) -------------------------------------------------------------------------------- Root Exception stack trace: >>>>> org.mule.api.routing.filter.FilterUnacceptedException: Message has been rejected by filter. Message payload is of type: byte[]` – Rizwan Sohaib Dec 25 '13 at 06:24
  • Again, I reviewed my proposed answer to try to avoid the `FilterUnacceptedException`. There are so many possible combinations in Mule that it's not always easy to find the right one :$ – David Dossot Dec 25 '13 at 17:44
  • Aaaah.... you are right, it is very hard to find help for mule. they have no good documentation and forums.. Again it didn't worked.. This time no files downloaded and no error/exception raised.. It just started the app and nothing more.. – Rizwan Sohaib Dec 26 '13 at 06:19
  • 1
    After checking the source code, I understand what's happening. Though the XML config allows any filter to be used, the FTP inbound endpoint only recognizes filters are that are actual implementation of `java.io.FilenameFilter`. And so far I can't locate any Mule-provided `java.io.FilenameFilter` implementation that is MEL-aware :( So you would have to create your own filter to make this work... – David Dossot Jan 09 '14 at 16:41
0

Use an expression filter #[server.dateTime.getWeekOfYear()].zip you can use this expression and customize your time format.