I\'ve set up a SOAP WebServiceProvider in JAX-WS, but I\'m having trouble figuring out how to get the raw XML from a SOAPMessage (or any Node) object. Here\'s a sample of t
If you have a SOAPMessage or SOAPMessageContext, you can use a Transformer, by converting it to a Source via DOMSource:
final SOAPMessage message = messageContext.getMessage();
final StringWriter sw = new StringWriter();
try {
TransformerFactory.newInstance().newTransformer().transform(
new DOMSource(message.getSOAPPart()),
new StreamResult(sw));
} catch (TransformerException e) {
throw new RuntimeException(e);
}
// Now you have the XML as a String:
System.out.println(sw.toString());
This will take the encoding into account, so your "special characters" won't get mangled.