Reputation: 15
New to Camel. I'm trying to get the current DateTime to be a part of a filename. The key bit is here:
.to(s"sftp://$sftpStr/&fileName=MyFile_${date:now:yyyyMMdd}.csv&noop=true")
sftpStr
contains the relevant path. But the Date expression throws an error on compilation. I'm sure it's something simple and stupid I'm doing, but it's not clear to me why this doesn't work.
There is a related thing I don't understand, which might help give context to my confusion. I tried this:
.log(LoggingLevel.INFO, LOG.getName, s"Route Started! Time = ${date:now:dd-MM-yyyy HH:mm:ss z}")
which threw an error. But I took away the s
tag in the string, and it worked fine. I thought the s
just signaled to read the string that follows as a simple expression.
To reiterate, basically just looking to capture the current date/time in a filename (and I can't just create a variable using, say, java.time.LocalDateTime.now()
or whatever for reasons too annoying to get into). I included the bit about the log to hopefully contextualize my confusion.
Thanks!
Upvotes: 0
Views: 3371
Reputation: 896
In the statement that you write the problem i believe is $sftpStr
. I think that this cannot be resolved.
$sftpStr
is a property then you should use {{$sftpStr}}
.${header.sftpStr}
.I propose to use headers for both folder and file name. Something like:
from(...)
...
.setHeader("folder", constant("the value"))
.setHeader("CamelFileName", simple("${date:now:yyyyMMdd}"))
.to("sftp:username:password@{{ftp.server}}/${header.folder}&noop=true");
In the above ftp.server
is a property that holds the SFTP host.
Hope that will help.
Upvotes: 1