A method to get the SOAP message from the input stream. - Java javax.xml.soap

Java examples for javax.xml.soap:SOAPMessage

Description

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

Demo Code

/****************************************************************************
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 .j  av a2s .c o  m

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
 ****************************************************************************/
//package com.java2s;

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 Tutorials