Java SOAP Message toPrettyString(SOAPMessage response)

Here you can find the source of toPrettyString(SOAPMessage response)

Description

to Pretty String

License

Apache License

Declaration

public static String toPrettyString(SOAPMessage response) throws TransformerException, SOAPException 

Method Source Code


//package com.java2s;
/*//from   w  w  w. j a  v a 2 s . c  o  m
 * Copyright 2013-2017 Simba Open Source
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import java.io.StringWriter;

public class Main {
    public static String toPrettyString(SOAPMessage response) throws TransformerException, SOAPException {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        Source content = response.getSOAPPart().getContent();
        StringWriter writer = new StringWriter();
        StreamResult result = new StreamResult(writer);
        transformer.transform(content, result);
        return writer.toString();
    }
}

Related

  1. printSoapFaultException(SOAPFaultException sfe)
  2. printSOAPMessage(SOAPMessage msg, String titol)
  3. printTree(NodeList childNodes, String padding, ByteArrayOutputStream byteArrayOS)
  4. saveMimeHeaders(SOAPMessage msg, String fileName)
  5. toByteArray(SOAPMessage soapMessage)
  6. toSOAPMessage(String msgString)
  7. toSOAPPart(String xml)
  8. toSOAPPart(String xml)
  9. toString(SOAPMessage soapMessage)