on 04-08-2014 9:48 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
80 | |
24 | |
11 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.