on 04-29-2010 6:07 PM
Hello,
I would like to attached some payloads from SOAP HEADER or SOAP BODY I know that the module PayloadSwapBean is useful for the Payloads but it is possible for SOAP HEADER or SOAP BODY....or what can i do if i want to attach some of these?
Thanks!
Hi,
PayloadSwapBean will be useful while two different payloads. But in your case Payload swapBean is not useful, as the SOAPHeader and SOAPBody is part of single payload. So you can develop a adapter module to extract the payload and do the attachment in receiver communication channel.
some sample code given below...
ModuleData inputModuleData)
throws ModuleException {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss:SSS");
System.err.println("module process method started at :::"+sdf.format(new Date()));
byte[] bytedata = null;
try {
// get the XI message from the environment
Message msg = (Message)
inputModuleData.getPrincipalData();
// create a new payload
AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(),
AuditDirection.INBOUND);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,
"AttachmentModule: Started Execution");
XMLPayload payload = msg.getDocument();
//DOMParsing domp=new DOMParsing();
SAXParsing saxp=new SAXParsing();
System.err.println("before calling DOMParsing method :::"+sdf.format(new Date()));
String attachString=saxp.getAppendString(payload);
System.err.println("After calling DOMParsing method :::"+sdf.format(new Date()));
TextPayload attachment = msg.createTextPayload();
// provide attributes and content for the new payload
//XMLPayload payload = msg.getDocument();
//String str = payload.getText();
attachment.setName("Attachment");
attachment.setContentType("text/plain");
attachment.setText(attachString);
// add the new payload as attachment to the message
msg.addAttachment(attachment);
System.err.println("Before transforming :::"+sdf.format(new Date()));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(payload.getInputStream());
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer();
javax.xml.transform.Source src = new DOMSource(doc);
ByteArrayOutputStream myBytes = new ByteArrayOutputStream();
javax.xml.transform.Result dest = new StreamResult(myBytes);
transformer.transform(src, dest);
byte docContent[] = myBytes.toByteArray();
if(docContent != null)
{
payload.setContent(docContent);
inputModuleData.setPrincipalData(msg);
}
thanks,
madhu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.