Body with byte array issue in camel route
Issue
- We have the following code
private byte[] zipFiles(ArrayList<byte[]> files) throws IOException {
log.info(files.size());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
int i = 0;
for (byte[] pdf : files) {
ZipEntry entry = new ZipEntry("doc_" + i++ + ".pdf");
entry.setSize(pdf.length);
log.info("Pdf len: " + pdf.length);
zos.putNextEntry(entry);
zos.write(pdf);
zos.closeEntry();
}
baos.flush();
zos.close();
baos.close();
return baos.toByteArray();
}
- In a processor, we do
byte[] out = zipFiles("Araaylist files ");
exch.getIn().setBody(out, byte[].class);
-
When we write this output directly to the file system the zip file is correct !
e.g. to(file:/path/to/file) OK . Zip is ok -
When we return this body as cxfrs response , we get a corrupt file. This used to work correctly in version 6.0 / with cxrfs .
Also when we try to email this zip file / it comes out corrupt. Email go through an email queue .camel smtp .
Environment
- Red Hat JBoss Fuse
- 6.x
- Apache Camel
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.