SaajUtils { public static SOAPMessage loadMessage(Resource resource, MessageFactory messageFactory) throws SOAPException, IOException { InputStream is = resource.getInputStream(); try { MimeHeaders mimeHeaders = new MimeHeaders(); mimeHeaders.addHeader(TransportConstants.HEADER_CONTENT_TYPE, "text/xml"); mimeHeaders.addHeader(TransportConstants.HEADER_CONTENT_LENGTH, Long.toString(resource.getFile().length())); return messageFactory.createMessage(mimeHeaders, is); } finally { is.close(); } }  static int getSaajVersion(); static int getSaajVersion(SOAPMessage soapMessage); static int getSaajVersion(SOAPElement soapElement); static String getSaajVersionString(); static Name toName(QName qName, SOAPElement resolveElement); static QName toQName(Name name); static SOAPMessage loadMessage(Resource resource, MessageFactory messageFactory); static SOAPEnvelope getEnvelope(SOAPElement element); static SOAPElement getFirstBodyElement(SOAPBody body); static final int SAAJ_11; static final int SAAJ_12; static final int SAAJ_13; }
@Test public void testLoadMessage() throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactoryUtils.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(getClass().getResourceAsStream("soapMessage.xml")); SOAPMessage soapMessage = SaajUtils.loadMessage(new ClassPathResource("soapMessage.xml", getClass()), messageFactory); assertXMLEqual(soapMessage.getSOAPPart(), document); }