Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RoutesBuilder ProcessZipFile() {
return new RouteBuilder() {
private ProcessZipFileEntry fileProcessor = new ProcessZipFileEntry();
private MissingFilesProcessor missingFileProcessor = new MissingFilesProcessor();
public void configure() throws Exception {
// This is the location to look for the metadata file
// we move it to the 'staging' directory first
// once processed we more to 'completed'
// NB - The locking isn't sufficient for a multi-process application here
String fileEndpoint = "file://" + inputDir +
"?include=" + metaFileNameRegex +
"&preMove=" + stagingDir +
"&move=" + completedDir +
// The import directory for the zip files + filename
String zipFileEndpoint = "file://" + inputDir + "/";
// Base route to check for new meta-data csv files
// 1) clear out the array we will use to keep the list of exected files from the meta-data
// 2) Use the route 'processMetaFile' to process the csv and populate our array of expected files
// 3) Use a custom file loader to load the zip data file, use route 'processZipContents' to process
// the individual items in the zip
// 4) Log that we have completed the processing of this dataset
// 5) Waits for next file
.setProperty("expectedFiles").constant(new ArrayList<ItemHolder>())
.bean(new LoadZipFileProcessor(zipFileEndpoint,
"direct:processZipContents", errorDir, stagingDir, completedDir, 10 * 1000))
.bean( missingFileProcessor )
.log("All done")
// Read the meta-data file and extract the list of files we expect into an array
// The 'expectedFiles' array is stored in a property in the route for use later
.log("Processing ${file:name}")
.process(exchange -> {
List files = (List) exchange.getProperty("expectedFiles");
String line = exchange.getIn().getBody(String.class);
files.add(new ItemHolder(line));
// Process the Zip file
// 1) Extract each of the pdf files from the zip archive
// 2) Don't load the whole file - use streaming mode - just in case it's big
// 3) If the extracted file is in the manifest then use our custom 'processor'
// 4) Otherwise - Use the 'unknownFile' route to handle the unexpected file
// 5) All done
.split(new ZipSplitter())
.when(new IsInManifest())
// Stub error handling for unknown files
// 1) Log the error
// 2) Write the PDF to the error directory
.log("Unknown file found in zip : ${header.camelFileName}")
.to("file://" + errorDir + "?fileName=${header.camelFileName}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.