I am creating a file transfer route which is using move
to set a dynamic path where the file is moved after successful file transfer. I have also setup a notifier to keep track of file transfer events.
As the move path is dynamic, I need to get the evaluated path where file was moved after the file transfer. How can this path inside the notifier?
public class MyFtpServiceBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
getContext()
.getManagementStrategy()
.addEventNotifier(new MyFtpServiceNotifier());
from("file:C:/tmp/inputfolder?move=archive/${date:now:yyyyMMdd}/${file:onlyname}")
.routeId("myRoute")
.to("file:C:/tmp/outputfolder")
}
}
public class MyFtpServiceNotifier extends EventNotifierSupport {
@Override
public void notify(EventObject event) throws Exception {
Exchange exchange = ((AbstractExchangeEvent) event).getExchange();
if (event instanceof ExchangeSentEvent) {
// Want to get here the path where file was moved
}
}
@Override
public boolean isEnabled(EventObject event) {
return event instanceof AbstractExchangeEvent;
}
}
You could try to add a header to the exchange, something like:
.setHeader("FILE_PROCESSED").simple("archive/${date:now:yyyyMMdd}/${file:onlyname}")
I'm not sure how to do it in a notifier, but you can always add a Processor and use the FileEndpoint.getMove().evaluate()
method on the exchange to obtain the final moved file path.
For example:
@Override
public void process(final Exchange exchange) throws Exception {
File movedFile = null;
if (exchange.getFromEndpoint() instanceof FileEndpoint) {
FileEndpoint fileEndpoint = (FileEndpoint) exchange.getFromEndpoint();
String movePath = fileEndpoint.getMove().evaluate(exchange, String.class);
File inputDir = fileEndpoint.getFile();
movedFile = new File(inputDir, movePath);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.