Java SOAP Message extractXMLPayloadFromSOAPMessage(SOAPMessage messageSOAP)

Here you can find the source of extractXMLPayloadFromSOAPMessage(SOAPMessage messageSOAP)

Description

Extracts the payload from a SOAP message.

License

Open Source License

Parameter

Parameter Description
messageSOAP The SOAP message

Exception

Parameter Description
Exception SOAP API problem

Return

The XML payload as a DOM document

Declaration

public static Document extractXMLPayloadFromSOAPMessage(SOAPMessage messageSOAP) throws Exception 

Method Source Code


//package com.java2s;
/*/*  w w w  .  j a  v  a 2  s .  co  m*/
 * Copyright 2016 Mentor Graphics Corporation. All Rights Reserved.
 * <p>
 * Recipients who obtain this code directly from Mentor Graphics use it solely
 * for internal purposes to serve as example Java web services.
 * This code may not be used in a commercial distribution. Recipients may
 * duplicate the code provided that all notices are fully reproduced with
 * and remain in the code. No part of this code may be modified, reproduced,
 * translated, used, distributed, disclosed or provided to third parties
 * without the prior written consent of Mentor Graphics, except as expressly
 * authorized above.
 * <p>
 * THE CODE IS MADE AVAILABLE "AS IS" WITHOUT WARRANTY OR SUPPORT OF ANY KIND.
 * MENTOR GRAPHICS OFFERS NO EXPRESS OR IMPLIED WARRANTIES AND SPECIFICALLY
 * DISCLAIMS ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
 * OR WARRANTY OF NON-INFRINGEMENT. IN NO EVENT SHALL MENTOR GRAPHICS OR ITS
 * LICENSORS BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING LOST PROFITS OR SAVINGS) WHETHER BASED ON CONTRACT, TORT
 * OR ANY OTHER LEGAL THEORY, EVEN IF MENTOR GRAPHICS OR ITS LICENSORS HAVE BEEN
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 * <p>
 */

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import javax.xml.soap.SOAPMessage;

import javax.xml.soap.SOAPBodyElement;

import javax.xml.parsers.DocumentBuilderFactory;

import java.util.Iterator;

public class Main {
    /**
     * Extracts the payload from a SOAP message.
     * @param messageSOAP The SOAP message
     * @return The XML payload as a DOM document
     * @throws Exception SOAP API problem
     */
    public static Document extractXMLPayloadFromSOAPMessage(SOAPMessage messageSOAP) throws Exception {
        // Get the iterator of all child elements from sOAP body.
        for (Iterator iter = messageSOAP.getSOAPBody().getChildElements(); iter.hasNext();) {
            Object child = iter.next();
            if (child instanceof SOAPBodyElement) {
                // Import node in empty DOM document
                Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                Node node = doc.importNode((SOAPBodyElement) child, true);
                doc.appendChild(node);
                return doc;
            }
        }
        return null;
    }
}

Related

  1. createFault(String message)
  2. createSOAPFault(SOAPFault fault, Throwable cause)
  3. createSOAPRequestForPartnerCategories( String userId)
  4. ensureNamespaceDeclared(SOAPElement elem, String namespaceURI, String prefix)
  5. ensureNamespaceDeclared(SOAPElement element, String prefix, String nsURI)
  6. getAttachmentContentType(SOAPMessage message)
  7. getBody(SOAPMessage m)
  8. getBodyContent(SOAPBody body)
  9. getBytes(SOAPMessage soap)