How to extract the attachments from JBoss ESB Message and attach the zipped attachment to SMPT mail ?

Solution Unverified - Updated -

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 to SMPT 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 the jboss-soa-p-5.3.1/jboss-as/samples/quickstarts/aggregator/ quickstart which is shipped in the SOA-P installation. Please watch out for the demonstration in the AggregatedMessageAssembler.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's Attachment [2] interface supports adding images and documents in binary formats and compressed files as an ESB message attachments. Hence, users can convert the String payload of the ESB message attachment to byte array. And then add the byte array to a java.util.zip.ZipOutputStream to finally get the zipped version of the original attachment before sending it through SMTP 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