cancel
Showing results for 
Search instead for 
Did you mean: 

How to create an attachment in file adapter custom module?

Former Member
0 Kudos

Hi Gurus,

I have a requirement that File->Soap scenario, need to pass the message with an attachment to Soap adapter communicating with external application.

In the File channel I leverage the PayloadZipBean to zip the inbound flat file as a zip file right now, so the payload presents as zip file in pipeline now.

Now I want to add a custom module after the standard module PayloadZipBean to create an attachment using the zip file payload itself and compose the XML content to the payload as what I defined in IR/ESR structure.Anyone shed some light on this?

Thanks,

Rajesh

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Rajesh,

You can do the below steps to achieve your requirement (Code may vary to suit your needs, these are just a hint to approach your solution) :

1. Extract the zip file payload from the incoming module data

         Object obj = inputModuleData.getPrincipalData();

         Message msg = (Message)obj;

         Payload attachment = msg.getMainPayload();

2. Construct a new outgoing payload using DOM resembling the structure that you defined in your design.

       XMLPayload xmlpayload = msg.getDocument();

       DocumentBuilderFactory factory;

       factory = DocumentBuilderFactory.newInstance();

       DocumentBuilder builder = factory.newDocumentBuilder();

       Document document = builder.newDocument();

<Create your xml structure using DOM APIs>

// Transforming the DOM object to Stream object.

       TransformerFactory tfactory = TransformerFactory.newInstance();

       Transformer transformer = tfactory.newTransformer();

       Source src = new DOMSource(document);

       ByteArrayOutputStream out = new ByteArrayOutputStream();

       Result dest = new StreamResult(out);

       transformer.transform(src, dest);

       byte[] docContent = out.toByteArray();

3. Set the newly created xml structure as the new main payload

 

        xmlpayload.setContent(docContent);

        msg.setMainPayload(xmlpayload);

4. Add the original document (zip file) as an attachment to the main payload.

        msg.addAttachment(attachment);

5. Set the modified message to the inputModuleData and return it to the messaging system

         inputModuleData.setPrincipalData(msg);

         return inputModuleData;

Regards

Bikash

Former Member
0 Kudos

Bikash,

Seems that's what I'm expecting now, thanks a lot and I will try for a testing.

Thanks,

Rajesh

Answers (0)