A - Writing A Date Processor
Write a class that implements Processor interface so that you can get the Header.Date
from Exchange object and set it to whatever format you want to;
public class DateProcessor implements Processor {
private static final SimpleDateFormat SOURCE_DATE_FORMAT = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
private static final SimpleDateFormat TARGET_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
@Override
public void process(Exchange exchange) throws Exception {
String dateString = exchange.getIn().getHeader("Date", String.class);
Date date = SOURCE_DATE_FORMAT.parse(dateString);
exchange.getIn().setHeader("Date", TARGET_DATE_FORMAT.format(date));
}
}
B - Use Date Processor On Your Route
Use the Date Processor above within your route as follows;
private static void dateProcessorExample(CamelContext camelContext) throws Exception {
camelContext.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("your source here")
.process(new DateProcessor())
.to("your target here");
}
});
}