SoapUtils { public static String setActionInContentType(String contentType, String action) { Assert.hasLength(contentType, "'contentType' must not be empty"); if (StringUtils.hasText(action)) { Matcher matcher = ACTION_PATTERN.matcher(contentType); if (matcher.find() && matcher.groupCount() == 1) { StringBuffer buffer = new StringBuffer(); matcher.appendReplacement(buffer, "action=" + action); matcher.appendTail(buffer); return buffer.toString(); } else { return contentType + "; action=" + action; } } else { return contentType; } } private  SoapUtils(); static String escapeAction(String soapAction); static String extractActionFromContentType(String contentType); static String setActionInContentType(String contentType, String action);  }
@Test public void testSetActionInContentType() throws Exception { String soapAction = "http: String contentType = "application/soap+xml"; String result = SoapUtils.setActionInContentType(contentType, soapAction); Assert.assertEquals("Invalid SOAP action", soapAction, SoapUtils.extractActionFromContentType(result)); String anotherSoapAction = "http: String contentTypeWithAction = "application/soap+xml; action=http: result = SoapUtils.setActionInContentType(contentTypeWithAction, anotherSoapAction); Assert.assertEquals("Invalid SOAP action", anotherSoapAction, SoapUtils.extractActionFromContentType(result)); }