cancel
Showing results for 
Search instead for 
Did you mean: 

PayloadSwapBean it is possible for other branches?

Former Member
0 Kudos

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!

Accepted Solutions (0)

Answers (1)

Answers (1)

madhusudana_reddy2
Contributor
0 Kudos

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

Former Member
0 Kudos

yes i checked that i cant do that with the module PayloadSwapBean....thanks for the code...

regards,

lpbuff