apache camel - Read file locations from table and copy to specific folder using pollEnrich() -
i trying write camel route reads database table list of absolute file paths , copy files folder. file path created content instead of original content.
from("timer://testdatagen?repeatcount=1") .to("sql:" + positionsql + "?datasource=datasource") .split(body()) .to("file://" + positionlistdir ) .log("finished copying list of files.") please let me know missing here convert absolute file path actual file.
update #1.
below snippet invoking pollenrich(). instead pollenrich() copying no of files equal no of rows returned sql , not according file name previous exchange.
string positionlistsqloptions = "?datasource=datasource"; // string positionsrcdiroptions = "?noop=true&delay=500&readlockmarkerfile=false&filename=${header.positionfiletobecopied}"; string positionsrcdiroptions = "?noop=true&delay=500&readlockmarkerfile=false&filename=${body}"; string positionstagingdiroptionsforwriting = "?donefilename=${file:name}.done"; from("timer://testdatagen?repeatcount=1") .to("sql:" + positionlistsql + positionlistsqloptions) .split(body()) \\ getting column value resultset linkedcaseinsensitivemap , storing in body .process(new positionfeederprocessor()) .setheader("positionfiletobecopied", body()) .pollenrich("file://" + positionsrcdir + positionsrcdiroptions) // .pollenrich().simple("file://" + positionsrcdir + positionsrcdiroptions) .to("file://" + positionstagingdir + positionstagingdiroptionsforwriting) .log("finished copying list of files."); i still unable actual file name passed pollingenrich() endpoint. tried extracting body through header too. have gone wrong.
well, able without using pollenrich() @ all.
string positionlistsqloptions = "?datasource=datasource"; string positionsrcdiroptions = "?noop=true&delay=500&readlockmarkerfile=false&filename=${header.camelfilename}"; string positionstagingdiroptionsforwriting = "?filename=${header.position.file.name}&donefilename=${file:name}.done"; from("timer://testdatagen?repeatcount=1") .to("sql:" + positionlistsql + positionlistsqloptions) .routeid("copier:") .setheader("positionfilelist", body()) .log("creating list of position files ...") .split(body()) .process(new positionlistprocessor()) .setheader("position.file.name", body()) .setheader("position.dir.name", constant(positionsrcdir)) .process(new positionfileprocessor()) .choice() .when(body().isnull()) .log("position file not found. ${header.position.file.name}") .otherwise() .to("file://" + positionstagingdir + positionstagingdiroptionsforwriting) .log("position file copied src : " + "${header.camelfilenameproduced} ... ${headers} ..."); and here processors.
public class positionlistprocessor implements processor { public void process(exchange exchange) throws exception { linkedcaseinsensitivemap positionfilesresultset = (linkedcaseinsensitivemap) exchange.getin().getbody(); try { string positionfilestr = positionfilesresultset.get("pf_location_new").tostring(); } exchange.getout().setbody(positionfilestr.trim()); } catch (exception e) { } } } public class positionfileprocessor implements processor { public void process(exchange exchange) throws exception { string filename = exchange.getin().getbody(string.class); string filepath = exchange.getin().getheader("position.dir.name", string.class); uri uri = new uri("file:///".concat(filepath.concat(filename))); file file = new file(uri); if (!file.exists()) { logger.debug((string.format("file %s not found on %s", filename, filepath))); exchange.getin().setbody(null); } else { exchange.getin().setbody(file); } } }
Comments
Post a Comment