add DOM Document to SOAP Body (JAXM)
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mighty_Moses
Posted On:   Thursday, April 4, 2002 05:44 AM

I'm wondering how to add a DOM Tree as the Body content of a SOAPEnvelope. Am I blind ?

Situation:

I have a xml document (lets say in a file or already parsed to a DOM-document). Now i want to send this using SOAP (utilizing JAXM). How to accomplish this ? I only found extensive methods for operation on the elements itself, but nothing for the case you already have the content.
Please help!

Re: add DOM Document to SOAP Body (JAXM)

Posted By:   Sharath_Jonnalagadda  
Posted On:   Thursday, April 18, 2002 02:21 AM

hai moses,

here is one such solution.


imagine sMessage as JAXM's SOAPMessage Classes object.

and imagine doc1 is the xml document which u have to add to the soap message


import org.dom4j.*;


DocumentSource source = (DocumentSource)

sMessage.getSOAPPart().getContent();

Document doc = source.getDocument();

Element elem = doc.getRootElement();

List elements = elem.elements();


Element body = elements.get(elements.size() -1);


body.addChildElement(doc1.getRootElement());


DocumentSource dSource = new DocumentSource(doc1);


sMessage.getSOAPPart().setContent(dSource);


sMessage.saveChanges();

sMessage.writeTo(System.out);


these steps should do the magic for u.


cheers

sharath.

Re: add DOM Document to SOAP Body (JAXM)

Posted By:   vikas_pandya  
Posted On:   Thursday, April 4, 2002 10:45 AM

If you want to send xml document using SOAP(utilizing JAXM) then i would say easiest way to achieve this is using JAXM attachment (AttachmentPart API). pretty neat and clean way of sending documents as SOAP attachment.
About | Sitemap | Contact