Apache camel 从表中读取文件位置并使用pollEnrich()复制到特定文件夹

Apache camel 从表中读取文件位置并使用pollEnrich()复制到特定文件夹,apache-camel,camel-sql,Apache Camel,Camel Sql,我试图编写一个骆驼路由,读取数据库表以获取绝对文件路径列表,然后将这些文件复制到另一个文件夹。但是,仅将文件路径创建为内容,而不是原始内容 from("timer://testDataGen?repeatCount=1") .to("sql:" + positionSql + "?dataSource=dataSource") .split(body()) .to("file://" + positionlistDir ) .log("Finished c

我试图编写一个骆驼路由,读取数据库表以获取绝对文件路径列表,然后将这些文件复制到另一个文件夹。但是,仅将文件路径创建为内容,而不是原始内容

    from("timer://testDataGen?repeatCount=1")
    .to("sql:" + positionSql + "?dataSource=dataSource")
    .split(body())
    .to("file://" + positionlistDir )
    .log("Finished copying the list of Files.")
请让我知道我在这里缺少什么来将绝对文件路径转换为实际文件

更新#1.

下面的代码段正在调用pollEnrich()。但是pollEnrich()复制的文件数等于sql返回的行数,而不是根据上一次交换的文件名

        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 the column value from the resultset which is a LinkedCaseInsensitiveMap and storing in the body
        .process(new positionFeederProcessor()) 
        .setHeader("positionFileToBeCopied", body())
        .pollEnrich("file://" + positionSrcDir + positionSrcDirOptions)
//      .pollEnrich().simple("file://" + positionSrcDir + positionSrcDirOptions)
        .to("file://" + positionStagingDir + positionStagingDirOptionsForWriting)
        .log("Finished copying the list of Files.");

我仍然无法获取传递到pollingEnrich()端点的实际文件名。我试着从身体上提取它,也试着通过头部提取。可能出了什么问题。

to
定义中使用
文件
组件时,会生成包含exchange内容的文件,但不会读取文件。例如,您可以使用
处理器
处理器:

from("timer://testDataGen?repeatCount=1")
    .to("sql:" + positionSql + "?dataSource=dataSource")
    .split(body())
    .pollEnrich().simple("file:folder?fileName=${body}")
    .to("file://" + positionlistDir )
    .log("Finished copying the list of Files.")

最后,我可以不用使用pollRich()来完成这项工作

这是处理器

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);
    }
} }

谢谢你的回复。上面的pollRich()调用实际上不起作用。在split()调用之后未处理消息。我以不同的方式工作,但不正确。编辑问题中的上述代码。。
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);
    }
} }