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 Message
and attach the zipped attachment toSMPT
mail ?
Resolution
- In order to read the
ESB message
attachment 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-P
installation. Please watch out for the demonstration in theAggregatedMessageAssembler.java
action 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 addingimages
anddocuments
inbinary
formats andcompressed
files as anESB message
attachments. Hence, users can convert theString
payload
of theESB message
attachment tobyte array
. And then add thebyte array
to ajava.util.zip.ZipOutputStream
to finally get thezipped version
of the original attachment before sending it throughSMTP
mail.
[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.
Comments