SoapUtilities { public static SOAPMessage stringToSoap( String soapString ) throws SOAPException { byte[] bytes; try { bytes = soapString.getBytes( "UTF-8" ); } catch ( UnsupportedEncodingException e ) { log.fatal( "### Error - this should never happen: " + e.getMessage() ); bytes = "".getBytes(); } String protocol; if ( soapString.contains( SOAP_11_NAMESPACE_URL ) ) { protocol = javax.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL; } else if ( soapString.contains( SOAP_12_NAMESPACE_URL ) ) { protocol = javax.xml.soap.SOAPConstants.SOAP_1_2_PROTOCOL; } else { throw new SOAPException( "Could't not detect SOAP protocol Version" ); } SOAPMessage sm; try { sm = MessageFactory.newInstance( protocol ).createMessage( null, new ByteArrayInputStream( bytes ) ); } catch ( IOException e ) { log.fatal( "### Error - this should never happen: " + e.getMessage() ); sm = MessageFactory.newInstance().createMessage(); } return sm; }  static SOAPMessage stringToSoap( String soapString ); static String soapToString( SOAPElement element ); static Document stringToDom( String xmlString ); static List<SOAPElement> getSoapChilds( SOAPElement ele, QName name ); static List<SOAPElement> getSoapChilds( SOAPElement ele ); static List<SOAPElement> inputNeeded( SOAPElement ele ); static Map<String, String> allNamespaces( SOAPElement ele ); static List<SOAPElement> getParents( SOAPElement e ); static SOAPElement getRoot( SOAPElement e ); static final String SOAP_11_NAMESPACE_URL; static final String SOAP_12_NAMESPACE_URL; }
@Test public void testStringToSoapCorrect() throws Exception { String msg = new String( MESSAGE ); stringToSoap( msg ); }
@Test( expected = SOAPException.class ) public void testStringToSoapBadFormated() throws Exception { String msg = new String( MESSAGE ).substring( 0, MESSAGE.length() - 2 ); SOAPMessage soap = stringToSoap( msg ); soap.getSOAPBody().getLocalName(); }