Java ApacheCamel PollEnrich:如何将文件体从PollEnrich解析为POJO以与初始文件聚合?

Java ApacheCamel PollEnrich:如何将文件体从PollEnrich解析为POJO以与初始文件聚合?,java,spring-boot,csv,apache-camel,spring-camel,Java,Spring Boot,Csv,Apache Camel,Spring Camel,我在使用spring boot应用程序和apache camel时遇到以下情况: 从sftp读取csv文件 在列表中强制转换其csv行,并用父POJO将其包装(父POJO包含2个列表,1个用于步骤1中的数据,第2个列表用于csv 2的数据(请参见步骤3) 从sftp服务器读取另一个csv文件 在列表中强制转换其数据,并从步骤2将其添加到原始父dto/exchange 当父POJO以列表的形式包含所有数据时,处理和转换数据 marshall转换为xml并写入sftp服务器 第1步和第2步似乎有效,

我在使用spring boot应用程序和apache camel时遇到以下情况:

  • 从sftp读取csv文件
  • 在列表中强制转换其csv行,并用父POJO将其包装(父POJO包含2个列表,1个用于步骤1中的数据,第2个列表用于csv 2的数据(请参见步骤3)
  • 从sftp服务器读取另一个csv文件
  • 在列表中强制转换其数据,并从步骤2将其添加到原始父dto/exchange
  • 当父POJO以列表的形式包含所有数据时,处理和转换数据
  • marshall转换为xml并写入sftp服务器
  • 第1步和第2步似乎有效,根据我从camel docu收集的信息,我现在需要使用“PollRich”从sftp服务器加载第二个CSV文件。现在我面临的问题是如何将文件2的数据与文件1的数据聚合

    我有以下问题:

    • PollRich的exchange正文是一个远程文件。教程显示,他们将其强制转换为file.class,这会导致异常
    • 成功投下后,如何加入两家交易所
    那么,如何使用pollRich获取文件并将其数据添加到POJO中呢

    我正在尝试类似于: 路线:

    文件名处理器: 工作时,结果是parentDto与包含文件1中所有csv行的列表交换

    @Service
    public class FileNameProcessor implements Processor {
    
        private static final String OUTPUT_FILE_FORMAT = ".xml";
    
        @Override
        public void process(final Exchange exchange) throws Exception {
            String inputFileName = exchange.getIn().getHeader("CamelFileNameOnly").toString();
            inputFileName = inputFileName.substring(0, inputFileName.length() - 4);
            final String outputFileName = inputFileName + OUTPUT_FILE_FORMAT;
            exchange.getIn().setHeader("CamelFileNameOnly", outputFileName);
    
            final List<CrmCsvRow> crmCsvRowList = exchange.getIn().getBody(ArrayList.class);
            final ParentDto parent = new ParentDto();
            parent.setCsvRowList(crmCsvRowList);
            exchange.getIn().setBody(parent);
        }
    }
    
    @服务
    公共类FileNameProcessor实现处理器{
    私有静态最终字符串输出文件格式=“.xml”;
    @凌驾
    公共作废进程(最终交换)引发异常{
    String inputFileName=exchange.getIn().getHeader(“CamelFileNameOnly”).toString();
    inputFileName=inputFileName.substring(0,inputFileName.length()-4);
    最终字符串outputFileName=输入文件名+输出文件格式;
    exchange.getIn().setHeader(“CamelFileNameOnly”,outputFileName);
    最终列表crmCsvRowList=exchange.getIn().getBody(ArrayList.class);
    final ParentDto parent=新ParentDto();
    parent.setCsvRowList(crmCsvRowList);
    exchange.getIn().setBody(父对象);
    }
    }
    
    元数据聚合器:

    @Service
    @Slf4j
    public class MetaDataAggregator implements AggregationStrategy {
        public Exchange aggregate(final Exchange oldExchange, final Exchange newExchange) {
            if (oldExchange == null) {
                return newExchange;
            }
            return this.aggregateData(oldExchange, newExchange);
        }
    
        private Exchange aggregateData(final Exchange oldExchange, final Exchange newExchange) {
           // Cast fails, saying it is a remote file cannot cast, but internet tutorials show this line of code working
            final File file = newExchange.getIn().getBody(File.class);
            // cast to POJO and add to "oldExchange" body
           // ... <HELP NEEDED>
            return oldExchange;
        }
    }
    
    @服务
    @Slf4j
    公共类MetaDataAggregator实现AggregationStrategy{
    公共交易所合计(最终交易所旧交易所、最终交易所新交易所){
    if(oldExchange==null){
    返回newExchange;
    }
    返回此.aggregateData(旧交换、新交换);
    }
    专用交换聚合数据(最终交换旧交换、最终交换新交换){
    //Cast失败,说它是一个远程文件,无法进行Cast,但internet教程显示这行代码正常工作
    最终文件File=newExchange.getIn().getBody(File.class);
    //转换为POJO并添加到“oldExchange”正文
    // ... 
    退换货;
    }
    }
    
    一般来说,我需要知道如何在聚合器中访问file2的数据,以便处理完整的父dto

    非常感谢您的帮助

    谢谢

    @Service
    @Slf4j
    public class MetaDataAggregator implements AggregationStrategy {
        public Exchange aggregate(final Exchange oldExchange, final Exchange newExchange) {
            if (oldExchange == null) {
                return newExchange;
            }
            return this.aggregateData(oldExchange, newExchange);
        }
    
        private Exchange aggregateData(final Exchange oldExchange, final Exchange newExchange) {
           // Cast fails, saying it is a remote file cannot cast, but internet tutorials show this line of code working
            final File file = newExchange.getIn().getBody(File.class);
            // cast to POJO and add to "oldExchange" body
           // ... <HELP NEEDED>
            return oldExchange;
        }
    }