public static byte [ ] getSoapMessageAsByte ( String version , List headerBlocks , Element body , String encoding ) throws Exception { Document message = createSoapMessage ( version , headerBlocks , body ) ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( ) ; TransformerFactory tf = TransformerFactory . newInstance ( ) ; // Fortify Mod: prevent external entity injection tf . setFeature ( XMLConstants . FEATURE_SECURE_PROCESSING , true ) ; Transformer t = tf . newTransformer ( ) ; // End Fortify Mod t . setOutputProperty ( OutputKeys . ENCODING , encoding ) ; t . transform ( new DOMSource ( message ) , new StreamResult ( baos ) ) ; // System.out.println("SOAP MESSAGE : " + baos.toString()); return baos . toByteArray ( ) ; }
A method to create a SOAP message and retrieve it as byte .