Here you can find the source of getSOAPMessageAsString(SOAPMessage soapMessage)
public static String getSOAPMessageAsString(SOAPMessage soapMessage)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import javax.xml.soap.SOAPMessage; import javax.xml.transform.OutputKeys; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; public class Main { public static String getSOAPMessageAsString(SOAPMessage soapMessage) { try {//from w w w . j av a 2 s .c om TransformerFactory tff = TransformerFactory.newInstance(); Transformer tf = tff.newTransformer(); tf.setOutputProperty(OutputKeys.INDENT, "yes"); tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); Source sc = soapMessage.getSOAPPart().getContent(); ByteArrayOutputStream streamOut = new ByteArrayOutputStream(); StreamResult result = new StreamResult(streamOut); tf.transform(sc, result); return streamOut.toString(); } catch (Exception e) { System.out.println("Exception in getSOAPMessageAsString " + e.getMessage()); return null; } } }