Java SOAP Message getSOAPMessageAsString(SOAPMessage soapMessage)

Here you can find the source of getSOAPMessageAsString(SOAPMessage soapMessage)

Description

get SOAP Message As String

License

Apache License

Declaration

public static String getSOAPMessageAsString(SOAPMessage soapMessage) 

Method Source Code


//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;
        }

    }
}

Related

  1. getSOAPHeaderElement(SOAPMessage message, String headerName, String nameSpace)
  2. getSOAPMessage(InputStream in)
  3. getSOAPMessage(InputStream is)
  4. getSOAPMessage(Map headerMap, InputStream is)
  5. getSOAPMessage(Source msg)
  6. getSoapMessageString(SOAPMessage message)
  7. getSOAPMsgFactory()
  8. getString(SOAPMessage msg)
  9. hasAttachments(SOAPMessage message)