Getting Raw XML From SOAPMessage in Java?

It turns out that one can get the raw XML by using Provider, in this way.

It turns out that one can get the raw XML by using Provider, in this way: @ServiceMode(value=Service.Mode. PAYLOAD) @WebServiceProvider() public class SoapProvider implements Provider { public Source invoke(Source msg) { StreamResult sr = new StreamResult(); ByteArrayOutputStream out = new ByteArrayOutputStream(); sr. SetOutputStream(out); Transformer trans = TransformerFactory.newInstance().newTransformer(); trans.

Transform(source, sr); // Use out to your heart's desire. } } I've ended up not needing this solution, so I haven't actually tried this code myself - it might need some tweaking to get right. But I know this is the right path to go down to get the raw XML from a web service.(I'm not sure how to make this work if you absolutely must have a SOAPMessage object, but then again, if you're going to be handling the raw XML anyways, why would you use a higher-level object?).

You could try in this way. SOAPMessage msg = messageContext.getMessage(); ByteArrayOutputStream out = new ByteArrayOutputStream(); msg. WriteTo(out); String strMsg = new String(out.toByteArray()).

If you need formatting the xml string to xml, try this: String xmlStr = "your-xml-string"; Source xmlInput = new StreamSource(new StringReader(xmlStr)); Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer. SetOutputProperty(OutputKeys. INDENT, "yes"); transformer.

SetOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer. Transform(xmlInput, new StreamResult(new FileOutputStream("response. Xml"))).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions