apache-camelunmarshallingsplittercamel-zipfile

can't get Camel unmarshal zipfile working?


I have a compressed or ZIP file inbound on camel route. This zip file has multiple CSV files within. I also need to condition the file content before further processing. It seems I can successfully unzip the file but cannot work on it is unmarshalled. It seems that multiple splitters are a problem. ??? hoping someone can tell me what I'm doing wrong. If I take the files out of the zip file, I can process them all individually, but I can't process them from the zip file.

I've tried ZipFileDataFormat, also ZipSplitter with same results. tried .split(bodyAs(Iterator.class))

        } else if (Boolean.parseBoolean(isCompressedOnly)) { //Only Zipped or Compressed

            ZipFileDataFormat zipFile = new ZipFileDataFormat();
            zipFile.setUsingIterator(true);

            from(fromStr)
            .routeId(routeId)
            .log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
            .unmarshal(zipFile)
            .split(body(Iterator.class))
            .streaming()
            .convertBodyTo(String.class)
            .wireTap("file:" + fileArchive)
            .split(body()).streaming()
            .process(new EndpointParametersProcessor(decoderName))
            .to(toStr)
            .end();

Solution

  • adding tokenize("\n") in the splitter operation that works on the individual csv files appears to have corrected my problem. also, to rejoin the message records to a single packet, include an aggregation strategy.

            } else if (Boolean.parseBoolean(isCompressedOnly)) { //Only Zipped or Compressed
    
                ZipFileDataFormat zipFile = new ZipFileDataFormat();
                zipFile.setUsingIterator(true);
    
                from(fromStr)
                .routeId("Zipped.Only")
                .log(LoggingLevel.INFO, "Message received ${file:name} for Only Zipped or Compressed files from host " + host)
                .unmarshal(zipFile)
                .split(body(Iterator.class))
                .streaming()
                .convertBodyTo(String.class)
                .wireTap("file:" + fileArchive)
                .split(body().tokenize("\n"), new FleetAggregationStrategy()).streaming()
                .process(new EndpointParametersProcessor(decoderName))
                .end()
                .to(toStr);