You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Mills, Gary (GE Digital)" <ga...@ge.com> on 2016/11/01 15:58:18 UTC

zipfile question - thank you

Camel users, ( thank you )
My project is to receive a zip compressed and encrypted file attachment from a customer, naturally, decompress and decrypt the attachment via email transfer.

I am only focusing on the zip portion now because over email I can't get it to work.  Seems that the compression size changes when sent over email.

It seems my logic works, if I take the zip file and simply drop it in the route from my Jboss environment it works. I can zip, unzip, the file from command line and the camel route. However, if I send the file as an attachment over email, the file size changes, and of course it does not work and throws the error...
org.apache.camel.RuntimeCamelException: java.util.zip.ZipException: invalid code lengths set

which suggests the zip file attachment has been altered during its transfer over email. The original file size is 9044 Bytes, after email xfr becomes, 15580 Bytes.  If I try opening it from the OS with unzip, gunzip, it shows:

[root@alphprdfuse2i latest]# unzip ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
Archive:  ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
caution:  zipfile comment truncated
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  missing 3282862893 bytes in zipfile
  (attempting to process anyway)
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

I've tried changing the file extension to JPEG, PNG, ge, etc... with no success.

Does anyone know what I can do to get around this???

Thank you !!

Gary Mills


RE: zipfile question - thank you

Posted by "Mills, Gary (GE Digital)" <ga...@ge.com>.
Stephan, 

This is my code and what was changed to make it work.  The 2 commented statements, plus the wrapper. 

package com.ge.ip.cfi.inboundemail.processors;

import java.io.BufferedWriter;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.activation.DataHandler;
import javax.mail.Address;
import javax.mail.Message;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.log4j.Logger;

import com.ge.ip.cfi.inboundemail.entities.FilenameAndContents;
import com.ge.ip.cfi.inboundemail.exception.EmailProcessorException;

public class EmailProcessor implements Processor {

	private static final Logger LOG = Logger.getLogger(EmailProcessor.class);

	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");

	public void process(Exchange exchange) throws Exception {

		LOG.info("Entering EmailProcessor...");

		Map<String, DataHandler> attachments = exchange.getIn().getAttachments();

		if ((null == attachments) || (attachments.size() < 1)) {
			throw new EmailProcessorException("Null or 0 attachements");
		} else {
			LOG.info("attachments.size = " + attachments.size());
		}

		Map<String, String> emailAttr = gatherEmailHeaderInformation(exchange);

		List<String> attachmentFilenames = new ArrayList<String>();

		try {

			List<FilenameAndContents> attachmentArray = new ArrayList<FilenameAndContents>();

			for (String name : attachments.keySet()) {

				DataHandler dh = attachments.get(name);
				String filename = dh.getName();

				//String contents = exchange.getContext().getTypeConverter().convertTo(String.class, dh.getInputStream());
				byte[] contents = exchange.getContext().getTypeConverter().convertTo(byte[].class, dh.getInputStream());
				LOG.info("Attachment file name: " + filename);
				attachmentFilenames.add(filename);

				FilenameAndContents attachmentFile = new FilenameAndContents();
				//attachmentFile.setFileContents(new String(contents));
				attachmentFile.setFileContents(contents);
				attachmentFile.setFileName(filename);
				attachmentArray.add(attachmentFile);

			}

			exchange.getIn().setBody(attachmentArray);

		} catch (org.apache.camel.TypeConversionException tce) {
			throw new EmailProcessorException(
					"Unable to type convert from file to string", tce);
		} catch (java.io.IOException ioe) {
			throw new EmailProcessorException(
					"IOException while obtaining Input Stream", ioe);
		} catch (java.lang.UnsupportedOperationException uoe) {
			throw new EmailProcessorException(
					"UnsupportedOperationException add operation is not supported by list",
					uoe);
		} catch (java.lang.ClassCastException cce) {
			throw new EmailProcessorException(
					"ClassCastException element prevents it from being added to list",
					cce);
		} catch (java.lang.NullPointerException npe) {
			throw new EmailProcessorException(
					"NullPointerException element is null", npe);
		} catch (java.lang.IllegalArgumentException iae) {
			throw new EmailProcessorException(
					"IllegalArgumentException property of element prevents it from being added to list",
					iae);
		}

		archiveEmail(emailAttr, attachmentFilenames, exchange);

		LOG.info("Exiting EmailProcessor.");
	}

	private Map<String, String> gatherEmailHeaderInformation(Exchange exchange) {

		final String emailBody = exchange.getIn().getBody(String.class);

		final Message mailMessage = exchange.getIn().getBody(javax.mail.Message.class);

		Map<String, String> attr = new HashMap<String, String>();

		try {
			if (null != mailMessage) {

				final Address[] fromArray = mailMessage.getFrom();
				if (null != fromArray) {
					String fromStr = convertAddressListToString(fromArray);
					attr.put("from", fromStr);
				}

				final Address[] toArray = mailMessage
						.getRecipients(javax.mail.Message.RecipientType.TO);
				if (null != toArray) {
					String toStr = convertAddressListToString(fromArray);
					attr.put("to", toStr);
				}

				final Address[] ccArray = mailMessage
						.getRecipients(javax.mail.Message.RecipientType.CC);
				if (null != ccArray) {
					String ccStr = convertAddressListToString(fromArray);
					attr.put("CC", ccStr);
				}

				final Address[] bccArray = mailMessage
						.getRecipients(javax.mail.Message.RecipientType.BCC);
				if (null != bccArray) {
					String bccStr = convertAddressListToString(fromArray);
					attr.put("BCC", bccStr);
				}

				final String subjectStr = mailMessage.getSubject();
				if (null != subjectStr) {
					attr.put("subject", subjectStr);
				}

				final Date sentDate = mailMessage.getReceivedDate();
				if (null != sentDate) {
					attr.put("sentDate", sdf.format(sentDate));
				}

				final Date receivedDate = mailMessage.getSentDate();
				if (null != receivedDate) {
					attr.put("receivedDate", sdf.format(receivedDate));
				}

				if (null != emailBody) {
					attr.put("body", emailBody);
				}

			}
		} catch (javax.mail.MessagingException me) {
			LOG.error("Unable to gather email header information");
		}

		return attr;

	}

	private void archiveEmail(Map<String, String> attr,
			List<String> attachmentFilenames, Exchange exchange) {

		final String archivePath = exchange.getIn().getHeader("emailArchive", String.class);

		Path parentP = Paths.get(archivePath);
		Path fileP;
		if (null != attr.get("receivedDate")) {
			fileP = Paths.get(archivePath, exchange.getExchangeId() + "." + attr.get("receivedDate"));
		} else {
			fileP = Paths.get(archivePath, exchange.getExchangeId());
		}

		try {
			Files.createDirectories(parentP);
		} catch (IOException ioe) {
			LOG.error("Unable to create email archive directories");
			ioe.printStackTrace();
		}

		Charset charset = Charset.forName("utf-8");

		try (BufferedWriter bufferedWriter = Files.newBufferedWriter(fileP,
				charset)) {

			if (null != attr.get("from")) {
				bufferedWriter.write("From:" + attr.get("from"));
				bufferedWriter.newLine();
			}

			if (null != attr.get("to")) {
				bufferedWriter.write("To:" + attr.get("to"));
				bufferedWriter.newLine();
			}

			if (null != attr.get("CC")) {
				bufferedWriter.write("CC:" + attr.get("CC"));
				bufferedWriter.newLine();
			}

			if (null != attr.get("BCC")) {
				bufferedWriter.write("BCC" + attr.get("BCC"));
				bufferedWriter.newLine();
			}

			if (null != attr.get("subject")) {
				bufferedWriter.write("Subject:" + attr.get("subject"));
				bufferedWriter.newLine();
			}

			if (null != attr.get("sentDate")) {
				bufferedWriter.write("Sent Date:" + attr.get("sentDate"));
				bufferedWriter.newLine();
			}

			if (null != attr.get("receivedDate")) {
				bufferedWriter.write("Received Date:"
						+ attr.get("receivedDate"));
				bufferedWriter.newLine();
			}

			if (null != attr.get("body")) {
				bufferedWriter.write("Body:" + attr.get("body"));
				bufferedWriter.newLine();
			}

			for (String s : attachmentFilenames) {
				bufferedWriter.write("Attachment File:" + s);
				bufferedWriter.newLine();
			}

		} catch (IOException ioe) {
			LOG.error("Unable to write email archive");
			ioe.printStackTrace();
		}

	}

	private String convertAddressListToString(Address[] adds) {

		String returnStr = "";

		for (Address adr : adds) {
			returnStr = returnStr + adr.toString() + " ";
		}

		return returnStr;

	}
}
package com.ge.ip.cfi.inboundemail.entities;

/***
 * DownloadFile is a simple POJO that is a wrapper around a
 * fileName and fileContents
 *
 */
public class FilenameAndContents {

	private String fileName;
	//private String fileContents;
	private byte[] fileContents;

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public byte[] getFileContents() {
		return fileContents;
	}
//	public byte[] getFileContents() {
//		return fileContents;
//	}

//	public void setFileContents(String fileContents) {
//		this.fileContents = fileContents;
//	}

	public void setFileContents(byte[] fileContents) {
		this.fileContents = fileContents;
	}

}
-----Original Message-----
From: Mills, Gary (GE Digital) 
Sent: Wednesday, November 02, 2016 9:18 AM
To: users@camel.apache.org
Subject: RE: zipfile question - thank you

Thank you so much Stephan for your response. I was thinking I was doing something wrong on these forums or email chats - thank you. You are completely right, I have that in place didn't share it yet.  However, I believe I have solved this.  It was type conversion - go figure, I was changing the type to String object instead of using the serialized entry byte stream.  After this change - I'm golden. 

Thank you again, 
Have a great day!
Gary

-----Original Message-----
From: Siano, Stephan [mailto:stephan.siano@sap.com] 
Sent: Wednesday, November 02, 2016 2:36 AM
To: users@camel.apache.org
Subject: EXT: RE: zipfile question - thank you

Hi,

how do you retreive the message from the mail server? On the server an email with a zip file attachment is actually a MIME-Multipart. One of the parts within that is the (usually base64 encoded) zip file. If you just read the message with some form(pop3:xxx) thing, and try to unmarshal that as a zip file, this will of course fail (because you are feeding the message body, not the attachment into it).

If you want to process the attachment, you will first need to add some processor that fetches the attachment from the message and puts the InputStream of the payload as the main message body.

Best regards
Stephan

-----Original Message-----
From: Mills, Gary (GE Digital) [mailto:gary.L.mills@ge.com] 
Sent: Dienstag, 1. November 2016 19:41
To: dev@camel.apache.org; users@camel.apache.org
Subject: RE: zipfile question - thank you

DefaultErrorHandler              | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | Failed delivery for (MessageId: ID-alphprdfuse2i-43262-1478008924653-2-36907 on ExchangeId: ID-alphprdfuse2i-43262-1478008924653-2-36908). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: java.lang.String but has value: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper@bcbe474 of type: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper on: Message: [Body is instance of java.io.InputStream]. Caused by: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set. Exchange[Message: [Body is instance of java.io.InputStream]]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set]

I am very confused.  If I take that zip file and simply drop it in the fileEntranceEndpoint everything works fine. If I send it through email it doesn't work. The only thing I've noticed is that the zip file appears to be corrupted after extracting the attachment and the above is what error is thrown.

Thank you

From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 11:52 AM
To: Mills, Gary (GE Digital) <ga...@ge.com>
Subject: RE: zipfile question - thank you

Update:

When I send an email to the endpoint email address, with an zip file attachment, and I open the zip file attachment directly from email endpoint mailbox, the zip file attachment opens ok.  It appears to be related to the extraction of the attachment in Camel ?

?????



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:34 AM
To: 'users-info@camel.apache.org' <us...@camel.apache.org>>
Subject: RE: zipfile question - thank you

Here is the code used to unmarshall the zip file

       public void configure() throws Exception {

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

              from(fileEntranceEndpoint).id("cfi.zipfile.endpointListenerRoute").log("Message received zip file: ${file:name}")
              .unmarshal(zipFile).split(body(Iterator.class)).streaming().convertBodyTo(String.class)
              .log("file names from ZipFile: ${file:name}").to("file://" + outDirectory);
       }



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:58 AM
To: 'dev@camel.apache.org' <de...@camel.apache.org>>
Subject: zipfile question - thank you

Camel users, ( thank you )
My project is to receive a zip compressed and encrypted file attachment from a customer, naturally, decompress and decrypt the attachment via email transfer.

I am only focusing on the zip portion now because over email I can't get it to work.  Seems that the compression size changes when sent over email.

It seems my logic works, if I take the zip file and simply drop it in the route from my Jboss environment it works. I can zip, unzip, the file from command line and the camel route. However, if I send the file as an attachment over email, the file size changes, and of course it does not work and throws the error...
org.apache.camel.RuntimeCamelException: java.util.zip.ZipException: invalid code lengths set

which suggests the zip file attachment has been altered during its transfer over email. The original file size is 9044 Bytes, after email xfr becomes, 15580 Bytes.  If I try opening it from the OS with unzip, gunzip, it shows:

[root@alphprdfuse2i latest]# unzip ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
Archive:  ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
caution:  zipfile comment truncated
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  missing 3282862893 bytes in zipfile
  (attempting to process anyway)
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

I've tried changing the file extension to JPEG, PNG, ge, etc... with no success.

Does anyone know what I can do to get around this???

Thank you !!

Gary Mills


RE: zipfile question - thank you

Posted by "Mills, Gary (GE Digital)" <ga...@ge.com>.
Thank you so much Stephan for your response. I was thinking I was doing something wrong on these forums or email chats - thank you. You are completely right, I have that in place didn't share it yet.  However, I believe I have solved this.  It was type conversion - go figure, I was changing the type to String object instead of using the serialized entry byte stream.  After this change - I'm golden. 

Thank you again, 
Have a great day!
Gary

-----Original Message-----
From: Siano, Stephan [mailto:stephan.siano@sap.com] 
Sent: Wednesday, November 02, 2016 2:36 AM
To: users@camel.apache.org
Subject: EXT: RE: zipfile question - thank you

Hi,

how do you retreive the message from the mail server? On the server an email with a zip file attachment is actually a MIME-Multipart. One of the parts within that is the (usually base64 encoded) zip file. If you just read the message with some form(pop3:xxx) thing, and try to unmarshal that as a zip file, this will of course fail (because you are feeding the message body, not the attachment into it).

If you want to process the attachment, you will first need to add some processor that fetches the attachment from the message and puts the InputStream of the payload as the main message body.

Best regards
Stephan

-----Original Message-----
From: Mills, Gary (GE Digital) [mailto:gary.L.mills@ge.com] 
Sent: Dienstag, 1. November 2016 19:41
To: dev@camel.apache.org; users@camel.apache.org
Subject: RE: zipfile question - thank you

DefaultErrorHandler              | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | Failed delivery for (MessageId: ID-alphprdfuse2i-43262-1478008924653-2-36907 on ExchangeId: ID-alphprdfuse2i-43262-1478008924653-2-36908). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: java.lang.String but has value: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper@bcbe474 of type: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper on: Message: [Body is instance of java.io.InputStream]. Caused by: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set. Exchange[Message: [Body is instance of java.io.InputStream]]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set]

I am very confused.  If I take that zip file and simply drop it in the fileEntranceEndpoint everything works fine. If I send it through email it doesn't work. The only thing I've noticed is that the zip file appears to be corrupted after extracting the attachment and the above is what error is thrown.

Thank you

From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 11:52 AM
To: Mills, Gary (GE Digital) <ga...@ge.com>
Subject: RE: zipfile question - thank you

Update:

When I send an email to the endpoint email address, with an zip file attachment, and I open the zip file attachment directly from email endpoint mailbox, the zip file attachment opens ok.  It appears to be related to the extraction of the attachment in Camel ?

?????



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:34 AM
To: 'users-info@camel.apache.org' <us...@camel.apache.org>>
Subject: RE: zipfile question - thank you

Here is the code used to unmarshall the zip file

       public void configure() throws Exception {

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

              from(fileEntranceEndpoint).id("cfi.zipfile.endpointListenerRoute").log("Message received zip file: ${file:name}")
              .unmarshal(zipFile).split(body(Iterator.class)).streaming().convertBodyTo(String.class)
              .log("file names from ZipFile: ${file:name}").to("file://" + outDirectory);
       }



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:58 AM
To: 'dev@camel.apache.org' <de...@camel.apache.org>>
Subject: zipfile question - thank you

Camel users, ( thank you )
My project is to receive a zip compressed and encrypted file attachment from a customer, naturally, decompress and decrypt the attachment via email transfer.

I am only focusing on the zip portion now because over email I can't get it to work.  Seems that the compression size changes when sent over email.

It seems my logic works, if I take the zip file and simply drop it in the route from my Jboss environment it works. I can zip, unzip, the file from command line and the camel route. However, if I send the file as an attachment over email, the file size changes, and of course it does not work and throws the error...
org.apache.camel.RuntimeCamelException: java.util.zip.ZipException: invalid code lengths set

which suggests the zip file attachment has been altered during its transfer over email. The original file size is 9044 Bytes, after email xfr becomes, 15580 Bytes.  If I try opening it from the OS with unzip, gunzip, it shows:

[root@alphprdfuse2i latest]# unzip ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
Archive:  ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
caution:  zipfile comment truncated
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  missing 3282862893 bytes in zipfile
  (attempting to process anyway)
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

I've tried changing the file extension to JPEG, PNG, ge, etc... with no success.

Does anyone know what I can do to get around this???

Thank you !!

Gary Mills


RE: zipfile question - thank you

Posted by "Siano, Stephan" <st...@sap.com>.
Hi,

how do you retreive the message from the mail server? On the server an email with a zip file attachment is actually a MIME-Multipart. One of the parts within that is the (usually base64 encoded) zip file. If you just read the message with some form(pop3:xxx) thing, and try to unmarshal that as a zip file, this will of course fail (because you are feeding the message body, not the attachment into it).

If you want to process the attachment, you will first need to add some processor that fetches the attachment from the message and puts the InputStream of the payload as the main message body.

Best regards
Stephan

-----Original Message-----
From: Mills, Gary (GE Digital) [mailto:gary.L.mills@ge.com] 
Sent: Dienstag, 1. November 2016 19:41
To: dev@camel.apache.org; users@camel.apache.org
Subject: RE: zipfile question - thank you

DefaultErrorHandler              | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | Failed delivery for (MessageId: ID-alphprdfuse2i-43262-1478008924653-2-36907 on ExchangeId: ID-alphprdfuse2i-43262-1478008924653-2-36908). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: java.lang.String but has value: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper@bcbe474 of type: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper on: Message: [Body is instance of java.io.InputStream]. Caused by: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set. Exchange[Message: [Body is instance of java.io.InputStream]]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set]

I am very confused.  If I take that zip file and simply drop it in the fileEntranceEndpoint everything works fine. If I send it through email it doesn't work. The only thing I've noticed is that the zip file appears to be corrupted after extracting the attachment and the above is what error is thrown.

Thank you

From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 11:52 AM
To: Mills, Gary (GE Digital) <ga...@ge.com>
Subject: RE: zipfile question - thank you

Update:

When I send an email to the endpoint email address, with an zip file attachment, and I open the zip file attachment directly from email endpoint mailbox, the zip file attachment opens ok.  It appears to be related to the extraction of the attachment in Camel ?

?????



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:34 AM
To: 'users-info@camel.apache.org' <us...@camel.apache.org>>
Subject: RE: zipfile question - thank you

Here is the code used to unmarshall the zip file

       public void configure() throws Exception {

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

              from(fileEntranceEndpoint).id("cfi.zipfile.endpointListenerRoute").log("Message received zip file: ${file:name}")
              .unmarshal(zipFile).split(body(Iterator.class)).streaming().convertBodyTo(String.class)
              .log("file names from ZipFile: ${file:name}").to("file://" + outDirectory);
       }



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:58 AM
To: 'dev@camel.apache.org' <de...@camel.apache.org>>
Subject: zipfile question - thank you

Camel users, ( thank you )
My project is to receive a zip compressed and encrypted file attachment from a customer, naturally, decompress and decrypt the attachment via email transfer.

I am only focusing on the zip portion now because over email I can't get it to work.  Seems that the compression size changes when sent over email.

It seems my logic works, if I take the zip file and simply drop it in the route from my Jboss environment it works. I can zip, unzip, the file from command line and the camel route. However, if I send the file as an attachment over email, the file size changes, and of course it does not work and throws the error...
org.apache.camel.RuntimeCamelException: java.util.zip.ZipException: invalid code lengths set

which suggests the zip file attachment has been altered during its transfer over email. The original file size is 9044 Bytes, after email xfr becomes, 15580 Bytes.  If I try opening it from the OS with unzip, gunzip, it shows:

[root@alphprdfuse2i latest]# unzip ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
Archive:  ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
caution:  zipfile comment truncated
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  missing 3282862893 bytes in zipfile
  (attempting to process anyway)
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

I've tried changing the file extension to JPEG, PNG, ge, etc... with no success.

Does anyone know what I can do to get around this???

Thank you !!

Gary Mills


RE: zipfile question - thank you

Posted by "Mills, Gary (GE Digital)" <ga...@ge.com>.
DefaultErrorHandler              | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | Failed delivery for (MessageId: ID-alphprdfuse2i-43262-1478008924653-2-36907 on ExchangeId: ID-alphprdfuse2i-43262-1478008924653-2-36908). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: java.lang.String but has value: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper@bcbe474 of type: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper on: Message: [Body is instance of java.io.InputStream]. Caused by: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set. Exchange[Message: [Body is instance of java.io.InputStream]]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set]

I am very confused.  If I take that zip file and simply drop it in the fileEntranceEndpoint everything works fine. If I send it through email it doesn't work. The only thing I've noticed is that the zip file appears to be corrupted after extracting the attachment and the above is what error is thrown.

Thank you

From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 11:52 AM
To: Mills, Gary (GE Digital) <ga...@ge.com>
Subject: RE: zipfile question - thank you

Update:

When I send an email to the endpoint email address, with an zip file attachment, and I open the zip file attachment directly from email endpoint mailbox, the zip file attachment opens ok.  It appears to be related to the extraction of the attachment in Camel ?

?????



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:34 AM
To: 'users-info@camel.apache.org' <us...@camel.apache.org>>
Subject: RE: zipfile question - thank you

Here is the code used to unmarshall the zip file

       public void configure() throws Exception {

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

              from(fileEntranceEndpoint).id("cfi.zipfile.endpointListenerRoute").log("Message received zip file: ${file:name}")
              .unmarshal(zipFile).split(body(Iterator.class)).streaming().convertBodyTo(String.class)
              .log("file names from ZipFile: ${file:name}").to("file://" + outDirectory);
       }



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:58 AM
To: 'dev@camel.apache.org' <de...@camel.apache.org>>
Subject: zipfile question - thank you

Camel users, ( thank you )
My project is to receive a zip compressed and encrypted file attachment from a customer, naturally, decompress and decrypt the attachment via email transfer.

I am only focusing on the zip portion now because over email I can't get it to work.  Seems that the compression size changes when sent over email.

It seems my logic works, if I take the zip file and simply drop it in the route from my Jboss environment it works. I can zip, unzip, the file from command line and the camel route. However, if I send the file as an attachment over email, the file size changes, and of course it does not work and throws the error...
org.apache.camel.RuntimeCamelException: java.util.zip.ZipException: invalid code lengths set

which suggests the zip file attachment has been altered during its transfer over email. The original file size is 9044 Bytes, after email xfr becomes, 15580 Bytes.  If I try opening it from the OS with unzip, gunzip, it shows:

[root@alphprdfuse2i latest]# unzip ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
Archive:  ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
caution:  zipfile comment truncated
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  missing 3282862893 bytes in zipfile
  (attempting to process anyway)
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

I've tried changing the file extension to JPEG, PNG, ge, etc... with no success.

Does anyone know what I can do to get around this???

Thank you !!

Gary Mills


RE: zipfile question - thank you

Posted by "Mills, Gary (GE Digital)" <ga...@ge.com>.
DefaultErrorHandler              | 198 - org.apache.camel.camel-core - 2.15.1.redhat-620133 | Failed delivery for (MessageId: ID-alphprdfuse2i-43262-1478008924653-2-36907 on ExchangeId: ID-alphprdfuse2i-43262-1478008924653-2-36908). Exhausted after delivery attempt: 1 caught: org.apache.camel.InvalidPayloadException: No body available of type: java.lang.String but has value: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper@bcbe474 of type: org.apache.camel.dataformat.zipfile.ZipInputStreamWrapper on: Message: [Body is instance of java.io.InputStream]. Caused by: Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set. Exchange[Message: [Body is instance of java.io.InputStream]]. Caused by: [org.apache.camel.TypeConversionException - Error during type conversion from type: java.lang.String to the required type: java.lang.String with value [Body is instance of java.io.InputStream] due java.util.zip.ZipException: invalid code lengths set]

I am very confused.  If I take that zip file and simply drop it in the fileEntranceEndpoint everything works fine. If I send it through email it doesn't work. The only thing I've noticed is that the zip file appears to be corrupted after extracting the attachment and the above is what error is thrown.

Thank you

From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 11:52 AM
To: Mills, Gary (GE Digital) <ga...@ge.com>
Subject: RE: zipfile question - thank you

Update:

When I send an email to the endpoint email address, with an zip file attachment, and I open the zip file attachment directly from email endpoint mailbox, the zip file attachment opens ok.  It appears to be related to the extraction of the attachment in Camel ?

?????



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:34 AM
To: 'users-info@camel.apache.org' <us...@camel.apache.org>>
Subject: RE: zipfile question - thank you

Here is the code used to unmarshall the zip file

       public void configure() throws Exception {

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

              from(fileEntranceEndpoint).id("cfi.zipfile.endpointListenerRoute").log("Message received zip file: ${file:name}")
              .unmarshal(zipFile).split(body(Iterator.class)).streaming().convertBodyTo(String.class)
              .log("file names from ZipFile: ${file:name}").to("file://" + outDirectory);
       }



From: Mills, Gary (GE Digital)
Sent: Tuesday, November 01, 2016 10:58 AM
To: 'dev@camel.apache.org' <de...@camel.apache.org>>
Subject: zipfile question - thank you

Camel users, ( thank you )
My project is to receive a zip compressed and encrypted file attachment from a customer, naturally, decompress and decrypt the attachment via email transfer.

I am only focusing on the zip portion now because over email I can't get it to work.  Seems that the compression size changes when sent over email.

It seems my logic works, if I take the zip file and simply drop it in the route from my Jboss environment it works. I can zip, unzip, the file from command line and the camel route. However, if I send the file as an attachment over email, the file size changes, and of course it does not work and throws the error...
org.apache.camel.RuntimeCamelException: java.util.zip.ZipException: invalid code lengths set

which suggests the zip file attachment has been altered during its transfer over email. The original file size is 9044 Bytes, after email xfr becomes, 15580 Bytes.  If I try opening it from the OS with unzip, gunzip, it shows:

[root@alphprdfuse2i latest]# unzip ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
Archive:  ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge
caution:  zipfile comment truncated
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  missing 3282862893 bytes in zipfile
  (attempting to process anyway)
error [ge-ip/core/tobeprocessed/archive/cfindustries.zip.ge]:  attempt to seek before beginning of zipfile
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

I've tried changing the file extension to JPEG, PNG, ge, etc... with no success.

Does anyone know what I can do to get around this???

Thank you !!

Gary Mills