问题
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..
回答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>
回答2:
Use an expression filter #[server.dateTime.getWeekOfYear()].zip you can use this expression and customize your time format.
来源:https://stackoverflow.com/questions/20704818/how-to-use-value-of-server-datetime-weekofyear-in-mule-app-properties-or-conf