I\'m implementing RESTful service (using CXFRS component) which should return files for some requests. Each file is fetched by its id and extension, i.e. restfulservice.co
Simple way often is the best way. I refuse to deal with Apache Camel file component in this case and implemented following processor:
public class FileLoadingProcessor implements Processor {
@Override
public void process(Exchange exchange) throws Exception {
String filename = exchange.getIn().getBody(String.class); // message body contains filename
String filePath = exchange.getIn().getHeader("fileprocessor.filepath", String.class);
if (filePath == null || filename == null) {
// throw some custom exception
}
URI uri = new URI(filePath.concat(filename));
File file = new File(uri);
if (!file.exists()) {
throw new FileNotFoundException(String.format("File %s not found on %s", filename, filePath));
}
exchange.getIn().setBody(file);
}
Now it's working like a charm