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
500788
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);
	   // Fortify Mod: Disable entity expansion to foil External Entity Injections
	   dbf.setExpandEntityReferences(false);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document soapMessage = db.newDocument();
          // Fortify Mod: prevent external entity injection
        TransformerFactory tf = TransformerFactory.newInstance();
        tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        Transformer t = tf.newTransformer();
	   // End Fortify Mod
        t.transform(new StreamSource(in), new DOMResult(soapMessage));
        return soapMessage;
    }
1371596
public static byte[] readSslMessage(InputStream in)
        throws IOException {
        byte [] header = new byte[5];
        readFully(in, header, 0, header.length);
	int length;
        if (isSSLv3Packet(header))
        	length = toShort(header[3], header[4]);
	else if (isSSLv2HelloPacket(header))
        	length = (((header[0] & 0x7f) << 8) | (header[1] & 0xff)) - 3;
	else {
            throw new IOException("Invalid SSL header");
        }
        byte [] inToken = new byte[header.length + length];
        System.arraycopy(header, 0, inToken, 0, header.length);
        readFully(in, inToken, header.length, length);
        return inToken;
    }
415636
public ServletInputStream getInputStream()
    {
        if (_inputState!=0 && _inputState!=1)
            throw new IllegalStateException();
        if (_in==null)
            _in = new ServletIn((HttpInputStream)_httpRequest.getInputStream());  
        _inputState=1;
        _reader=null;
        return _in;
    }
129819
@Override
    TarInputStream getInputStreamForRawStream(final InputStream in) throws IOException {
        assert in != null : "Specified inputstream was null";
        return new TarInputStream(in);
    }
188305
public static HttpResponse parseMessage(InputStream in) throws IOException {
        HttpResponse m = new HttpResponse();
        m.parse(in);
        return m;
    }
414745
protected InputStream getInputStream()
        throws IOException
    {
        if (is == null && server != null)
            is = server.readChannel(channel);

        return is;
    }
87980
@Override
  public Object getHeader(Stub soapClient, String headerName) {
    SOAPHeaderElement[] soapHeaders = soapClient.getHeaders();
    for (SOAPHeaderElement soapHeader : soapHeaders) {
      if (soapHeader.getName().equals(headerName)) {
        return soapHeader;
      }
    }
    return null;
  }
155788
@Override
	public String getMessage() {
		String ret = super.getMessage();
		if (fileName != null) {
			ret += (" in " + fileName);
			if (lineNumber != -1) {
				ret += " at line number " + lineNumber;
			}

			if (columnNumber != -1) {
				ret += " at column number " + columnNumber;
			}
		}

		return ret;
	}
1204281
protected Object getSOAPRequestObjects(SOAPMessageContext context) {
        // Obtain the operation details and message type
        // Extract the SOAP Message
        SOAPElement requestNode = getSOAPRequestNode(context);
        return unmarshall(requestNode);
    }
305130
public static InputStream toInputStream(String s)
    {
        InputStream is = new ByteArrayInputStream(s.getBytes());
        return is;
    }
494729
public SOAPElement getElement(SOAPElement element, String strElementName)
    {
        Iterator<?> iterator = element.getChildElements();
        while (iterator.hasNext())
        {
            javax.xml.soap.Node elMessageType = (javax.xml.soap.Node)iterator.next();
            if (elMessageType instanceof SOAPElement)
            {
                if (strElementName == null)
                    return (SOAPElement)elMessageType;    // The message type
                if (strElementName.equalsIgnoreCase(((SOAPElement)elMessageType).getElementName().getLocalName()))
                    return (SOAPElement)elMessageType;    // The message type
            }
        }
        return null;    // not found
    }
477785
public static SOAPMessage createSoapFromStream(Map<String,String> headers, InputStream is){
        return createSoapFromStream(null,headers,is);
    }
565678
public static Messaging getMessaging(final Jaxb2Marshaller jaxb2Marshaller, final WebServiceMessage message) {

        SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
        if (soapHeader == null) {
            throw new RuntimeException("The ebMS header is missing (no SOAP header found in SOAP request)");
        }

        Iterator<SoapHeaderElement> soapHeaderElementIterator = soapHeader.examineHeaderElements(MESSAGING_QNAME);
        if (!soapHeaderElementIterator.hasNext()) {
            throw new RuntimeException("The ebMS header is missing in SOAP header");
        }

        SoapHeaderElement incomingSoapHeaderElement = soapHeaderElementIterator.next();
        try {
            return (Messaging) jaxb2Marshaller.unmarshal(incomingSoapHeaderElement.getSource());
        } catch (Exception e) {
            throw new RuntimeException("The ebMs header failed to unmarshall");
        }

    }
1142410
public InputStream toInputStream() {
        
        String text = toXml();
        return new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
        
    }
371140
private boolean isSoapFault(Document soapMessage) throws Exception {
        Element faultElement = DomUtils.getElementByTagNameNS(soapMessage,
                SOAP_12_NAMESPACE, "Fault");

        if (faultElement != null) {
            return true;
        } else {
            faultElement = DomUtils.getElementByTagNameNS(soapMessage,
                    SOAP_11_NAMESPACE, "Fault");
            if (faultElement != null) {
                return true;
            }
        }
        return false;
    }
432365
public static byte[] readStream(InputStream in) {
        if(in == null){
            return null;
        }
        ByteArrayOutputStream out = null;
        try {
            out = new ByteArrayOutputStream();
            byte[] buf = new byte[1024 * 8];
            int length = 0;
            while((length = in.read(buf)) != -1){
                out.write(buf, 0, length);
            }
            return out.toByteArray();

        } catch (IOException e) {
            throw new IORuntimeException(e);

        } finally {
            closeQuietly(in);
            closeQuietly(out);
        }
    }
1129980
public InputStream getInputStream() throws APIException, IOException {
        final HttpResponse response = client.get(getUrl());
        HttpClientHelpers.throwIfNotOk(response);
        return response.getEntity().getContent();
    }