How to extract the attachments from JBoss ESB Message and attach the zipped attachment to SMPT mail ?
Environment
- Red Hat JBoss SOA Platform (SOA-P)
- 5.x
Issue
- How to extract the attachments from
JBoss ESB Messageand attach the zipped attachment toSMPTmail ?
Resolution
- In order to read the
ESB messageattachment the important thing to keep in mind would be to first de-serialize the attachments and then convert it to string object. It is properly shown in thejboss-soa-p-5.3.1/jboss-as/samples/quickstarts/aggregator/quickstart which is shipped in theSOA-Pinstallation. Please watch out for the demonstration in theAggregatedMessageAssembler.javaaction class as displayed below.
AggregatedMessageAssembler.java
...
public Message process(Message message) throws ActionProcessingException {
Attachment attachments = message.getAttachment();
int attachmentCount = attachments.getUnnamedCount();
StringBuffer assemblyBuffer = new StringBuffer();
for (int i = 0; i < attachmentCount; i++) {
try {
Message aggrMessage = Util.deserialize((Serializable) attachments.itemAt(i));
String payload = aggrMessage.getBody().get().toString();
assemblyBuffer.append("**** Payload from Message Attachment " + i + ":\n");
assemblyBuffer.append(payload + "\n");
} catch (Exception e) {
// Not an aggregated message attachment... continue...
}
}
...
- Once that is done the attachment can be written to a file and then attached to the email, just the way
EmailRouter[1] does it. - Now,
ESB'sAttachment[2] interface supports addingimagesanddocumentsinbinaryformats andcompressedfiles as anESB messageattachments. Hence, users can convert theStringpayloadof theESB messageattachment tobyte array. And then add thebyte arrayto ajava.util.zip.ZipOutputStreamto finally get thezipped versionof the original attachment before sending it throughSMTPmail.
[1] EmailRouter
[2] Message Attachment
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
