javaapache-camelapache-camel-mail

How to addAttachment on Camel 3.0


in Camel 2.x I could add an Attachment to a Message like:

exchange.getOut().addAttachment("LogFile.log.gz", new DataHandler(Base64.decodeBase64(FileContentBase64),"application/x-gzip"));

But in Camel 3.0 it is not possible. I change my code like the migration guide says:

exchange.getMessage().addAttachment("LogFile.log.gz", new DataHandler(Base64.decodeBase64(FileContentBase64),"application/x-gzip"));

But it is not working. Also this not:

exchange.getIn().addAttachment("LogFile.log.gz", new DataHandler(Base64.decodeBase64(FileContentBase64),"application/x-gzip"));

Have someone an idea, to solve this.

I want to e-Mail this Attachment.


Solution

  • Camel Version 3 was modularized a lot. So the attachments API was extracted and has to be used differently, see Camel 3 Migration Guide:

    The attachments API (javax.activation) has been moved out of org.apache.camel.message into an extension org.apache.camel.attachment.AttachmentMessage from the camel-attachments JAR.

    To use this API you can get it via the getMessage method on Exchange:

    AttachmentMessage am = exchange.getMessage(AttachmentMessage.class); am.addAttachment("myAtt", new DataHandler(...));