Java SOAP Message getSOAPMessage(InputStream in)

Here you can find the source of getSOAPMessage(InputStream in)

Description

A method to get the SOAP message from the input stream.

License

Mozilla Public License

Parameter

Parameter Description
in the input stream to be used to get the SOAP message.

Return

the SOAP message

Declaration

public static Document getSOAPMessage(InputStream in) throws Exception 

Method Source Code

//package com.java2s;
/****************************************************************************
The contents of this file are subject to the Mozilla Public License
Version 1.1 (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.mozilla.org/MPL///from w  ww  .ja v a 2s .  c om
    
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
the specific language governing rights and limitations under the License.
    
The Original Code is TEAM Engine.
    
The Initial Developer of the Original Code is Intecs SPA.  Portions created by
Intecs SPA are Copyright (C) 2008-2009, Intecs SPA. All Rights Reserved.
    
Contributor(s): No additional contributors to date
 ****************************************************************************/

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;

import javax.xml.transform.stream.StreamSource;

import org.w3c.dom.Document;

public class Main {
    /**
     * A method to get the SOAP message from the input stream.
     * 
     * @param in
     *            the input stream to be used to get the SOAP message.
     * 
     * @return the SOAP message
     * 
     * @author Simone Gianfranceschi
     */
    public static Document getSOAPMessage(InputStream in) throws Exception {
        /*
         * ByteArrayOutputStream out = new ByteArrayOutputStream(); int b; while
         * ((b = in.read()) != -1) { out.write(b); }
         * 
         * System.out.println("OUT:" + out.toString());
         */
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document soapMessage = db.newDocument();
        Transformer t = TransformerFactory.newInstance().newTransformer();
        t.transform(new StreamSource(in), new DOMResult(soapMessage));
        return soapMessage;
    }
}

Related

  1. getPrefix(String namespaceURI, SOAPElement contextElem)
  2. getSOAPData(SOAPMessage soapMessage)
  3. getSoapFaultExceptionMessage(SOAPFaultException sfe)
  4. getSOAPHeader(SOAPMessageContext smc)
  5. getSOAPHeaderElement(SOAPMessage message, String headerName, String nameSpace)
  6. getSOAPMessage(InputStream is)
  7. getSOAPMessage(Map headerMap, InputStream is)
  8. getSOAPMessage(Source msg)
  9. getSOAPMessageAsString(SOAPMessage soapMessage)