Well, not directly. Date: an object in a simple language can capture only the current time (or some time value that you placed inside the header), which you could do in java or similar.
But you can also do it. Create a class:
public class YesterdayBean{ public String getYesterday(){ Calendar cal = Calendar.getInstance(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); cal.add(Calendar.DATE, -1); return dateFormat.format(cal.getTime()); } }
Connect it to your camel (or spring, if you use this) registry as a bean. If you do not know how to do this, find the registry and the "Use" section of the bean .
Let's say you called bean "yesterday" in the registry, with spring:
<bean id="yesterday" class="some.package.YesterdayBean"/>
then just use it with the file component.
.to("file:fo/bar?fileName=${bean:yesterday}")
If this is just the one place you need and you are using Java DSL, you can also just create a date using the java processor and put it in the header.
Like this:
from("file:somewhere") .process(new Processor(){ public void process(Exchange ex){ Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -1); ex.getIn().setHeader("yesterday",cal.getTime()); } }) .to("file:target?fileName=${date:header.yesterday:dd-MM-yyyy}"); }
Petter nordlander
source share