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 ; }
A method to get the SOAP message from the input stream .