SoapUtils { public static String extractSoapBody(String soapEnvelope) { try { int pos1, pos2, pos3, pos4, pos5; pos1 = soapEnvelope.lastIndexOf("<"); pos1 = soapEnvelope.lastIndexOf("<", pos1 - 1); pos5 = soapEnvelope.indexOf(">", pos1); if (soapEnvelope.charAt(pos5 - 1) == '/') { return ""; } pos2 = soapEnvelope.indexOf(":", pos1); String soapPrefix = ((pos2 == -1) || (pos5 < pos2)) ? "" : soapEnvelope.substring(pos1 + 2, pos2 + 1); String bodyElementStart = new StringBuilder() .append('<') .append(soapPrefix) .append("Body") .toString(); pos3 = soapEnvelope.indexOf(bodyElementStart); pos4 = soapEnvelope.indexOf('>', pos3 + bodyElementStart.length()); return soapEnvelope.substring(pos4 + 1, pos1); } catch(Exception e) { LOG.error("Invalid contents, probably not a SOAP Envelope in the parameter", e); return soapEnvelope; } } private  SoapUtils(); static Element getElementNS(
            Element root,
            Set<String> nsUris,
            String wantedLocalName); static String extractSoapBody(String soapEnvelope); static String extractNonEmptyElement(String document, String elementName); static Exception extractOutgoingException(Exchange exchange); static String extractOutgoingPayload(Exchange exchange); static final Set<String> WS_ADDRESSING_NS_URIS; static final Set<String> SOAP_NS_URIS; }
@Test public void testExctractSoapBody() { assertEquals(contents, extractSoapBody(envelopeWithNamespacePrefixes)); assertEquals(contents, extractSoapBody(envelopeWithoutNamespacePrefixes)); assertEquals("", extractSoapBody(emptyEnvelopeWithNamespacePrefixes)); assertEquals("", extractSoapBody(emptyEnvelopeWithoutNamespacePrefixes)); assertEquals("", extractSoapBody(emptyEnvelopeWithNamespacePrefixesShort)); assertEquals("", extractSoapBody(emptyEnvelopeWithoutNamespacePrefixesShort)); Assert.assertNull(extractSoapBody(null)); Assert.assertEquals(totallyBad, extractSoapBody(totallyBad)); }