SWS-420
This commit is contained in:
@@ -82,5 +82,4 @@ public abstract class AbstractSoapMessage extends AbstractMimeMessage implements
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.ws.soap.AbstractSoapMessage;
|
||||
import org.springframework.ws.soap.SoapEnvelope;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.support.SoapUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
@@ -162,15 +163,7 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
}
|
||||
|
||||
public void setSoapAction(String soapAction) {
|
||||
if (soapAction == null) {
|
||||
soapAction = EMPTY_SOAP_ACTION;
|
||||
}
|
||||
if (!soapAction.startsWith("\"")) {
|
||||
soapAction = "\"" + soapAction;
|
||||
}
|
||||
if (!soapAction.endsWith("\"")) {
|
||||
soapAction = soapAction + "\"";
|
||||
}
|
||||
soapAction = SoapUtils.escapeAction(soapAction);
|
||||
this.soapAction = soapAction;
|
||||
}
|
||||
|
||||
@@ -230,8 +223,13 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
if (!hasAttachments) {
|
||||
contentType += "; charset=\"" + charsetEncoding + "\"";
|
||||
}
|
||||
if (SoapVersion.SOAP_11 == getVersion()) {
|
||||
transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
|
||||
}
|
||||
else if (SoapVersion.SOAP_12 == getVersion()) {
|
||||
contentType += "; action=" + soapAction;
|
||||
}
|
||||
transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
|
||||
transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
|
||||
}
|
||||
if (!(format.isOptimized()) & format.isDoingSWA()) {
|
||||
writeSwAMessage(outputStream, format);
|
||||
|
||||
@@ -48,6 +48,7 @@ import org.springframework.ws.soap.SoapMessageFactory;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor;
|
||||
import org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping;
|
||||
import org.springframework.ws.soap.support.SoapUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
@@ -179,15 +180,17 @@ public class AxiomSoapMessageFactory implements SoapMessageFactory, Initializing
|
||||
}
|
||||
|
||||
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
|
||||
if (!(inputStream instanceof TransportInputStream)) {
|
||||
throw new IllegalArgumentException("AxiomSoapMessageFactory requires a TransportInputStream");
|
||||
}
|
||||
Assert.isInstanceOf(TransportInputStream.class, inputStream,
|
||||
"AxiomSoapMessageFactory requires a TransportInputStream");
|
||||
TransportInputStream transportInputStream = (TransportInputStream) inputStream;
|
||||
String contentType = getHeaderValue(transportInputStream, TransportConstants.HEADER_CONTENT_TYPE);
|
||||
if (!StringUtils.hasLength(contentType)) {
|
||||
throw new IllegalArgumentException("TransportInputStream contains no Content-Type header");
|
||||
}
|
||||
String soapAction = getHeaderValue(transportInputStream, TransportConstants.HEADER_SOAP_ACTION);
|
||||
if (!StringUtils.hasLength(soapAction)) {
|
||||
soapAction = SoapUtils.extractActionFromContentType(contentType);
|
||||
}
|
||||
try {
|
||||
if (isMultiPartRelated(contentType)) {
|
||||
return createMultiPartAxiomSoapMessage(inputStream, contentType, soapAction);
|
||||
|
||||
@@ -36,7 +36,9 @@ import org.springframework.ws.mime.AttachmentException;
|
||||
import org.springframework.ws.soap.AbstractSoapMessage;
|
||||
import org.springframework.ws.soap.SoapEnvelope;
|
||||
import org.springframework.ws.soap.SoapMessage;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.soap.support.SoapUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
|
||||
/**
|
||||
@@ -96,22 +98,46 @@ public class SaajSoapMessage extends AbstractSoapMessage {
|
||||
|
||||
public String getSoapAction() {
|
||||
MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(getSaajMessage());
|
||||
String[] values = mimeHeaders.getHeader(TransportConstants.HEADER_SOAP_ACTION);
|
||||
return ObjectUtils.isEmpty(values) ? "" : values[0];
|
||||
if (SoapVersion.SOAP_11 == getVersion()) {
|
||||
String[] actions = mimeHeaders.getHeader(TransportConstants.HEADER_SOAP_ACTION);
|
||||
return ObjectUtils.isEmpty(actions) ? TransportConstants.EMPTY_SOAP_ACTION : actions[0];
|
||||
}
|
||||
else if (SoapVersion.SOAP_12 == getVersion()) {
|
||||
String[] contentTypes = mimeHeaders.getHeader(TransportConstants.HEADER_CONTENT_TYPE);
|
||||
return !ObjectUtils.isEmpty(contentTypes) ? SoapUtils.extractActionFromContentType(contentTypes[0]) :
|
||||
TransportConstants.EMPTY_SOAP_ACTION;
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("Unsupported SOAP version: " + getVersion());
|
||||
}
|
||||
}
|
||||
|
||||
public void setSoapAction(String soapAction) {
|
||||
if (soapAction == null) {
|
||||
soapAction = "";
|
||||
}
|
||||
MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(getSaajMessage());
|
||||
if (!soapAction.startsWith("\"")) {
|
||||
soapAction = "\"" + soapAction;
|
||||
soapAction = SoapUtils.escapeAction(soapAction);
|
||||
if (SoapVersion.SOAP_11 == getVersion()) {
|
||||
mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
|
||||
}
|
||||
if (!soapAction.endsWith("\"")) {
|
||||
soapAction = soapAction + "\"";
|
||||
else if (SoapVersion.SOAP_12 == getVersion()) {
|
||||
// force save of Content Type header
|
||||
if (saajMessage.saveRequired()) {
|
||||
try {
|
||||
saajMessage.saveChanges();
|
||||
}
|
||||
catch (SOAPException ex) {
|
||||
throw new SaajSoapMessageException("Could not save message", ex);
|
||||
}
|
||||
}
|
||||
String[] contentTypes = mimeHeaders.getHeader(TransportConstants.HEADER_CONTENT_TYPE);
|
||||
String contentType = !ObjectUtils.isEmpty(contentTypes) ? contentTypes[0] : getVersion().getContentType();
|
||||
contentType = SoapUtils.setActionInContentType(contentType, soapAction);
|
||||
mimeHeaders.setHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
|
||||
mimeHeaders.removeHeader(TransportConstants.HEADER_SOAP_ACTION);
|
||||
}
|
||||
mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
|
||||
else {
|
||||
throw new IllegalStateException("Unsupported SOAP version: " + getVersion());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeTo(OutputStream outputStream) throws IOException {
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.soap.support;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
|
||||
/**
|
||||
* Contains various utility methods for handling SOAP messages.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @since 1.5.5
|
||||
*/
|
||||
public abstract class SoapUtils {
|
||||
|
||||
private static final Pattern ACTION_PATTERN = Pattern.compile("action\\s*=\\s*([^;]+)");
|
||||
|
||||
private SoapUtils() {
|
||||
}
|
||||
|
||||
/** Escapes the given SOAP action to be surrounded by quotes. */
|
||||
public static String escapeAction(String soapAction) {
|
||||
if (soapAction == null) {
|
||||
soapAction = "";
|
||||
}
|
||||
if (!soapAction.startsWith("\"")) {
|
||||
soapAction = "\"" + soapAction;
|
||||
}
|
||||
if (!soapAction.endsWith("\"")) {
|
||||
soapAction = soapAction + "\"";
|
||||
}
|
||||
return soapAction;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the action parameter in the given SOAP 1.2 content type.
|
||||
*
|
||||
* @param contentType the SOAP 1.2 content type
|
||||
* @return the action
|
||||
*/
|
||||
public static String extractActionFromContentType(String contentType) {
|
||||
if (contentType != null) {
|
||||
Matcher matcher = ACTION_PATTERN.matcher(contentType);
|
||||
if (matcher.find() && matcher.groupCount() == 1) {
|
||||
return matcher.group(1).trim();
|
||||
}
|
||||
}
|
||||
return TransportConstants.EMPTY_SOAP_ACTION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces or adds the value of the action parameter in the given SOAP 1.2 content type.
|
||||
*
|
||||
* @param contentType the SOAP 1.2 content type
|
||||
* @param action the action
|
||||
* @return the new content type
|
||||
*/
|
||||
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);
|
||||
matcher.appendTail(buffer);
|
||||
return buffer.toString();
|
||||
}
|
||||
else {
|
||||
return contentType + "; action=" + action;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return contentType;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Classes supporting the org.springframework.ws.soap package.
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2008 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ws.soap.support;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class SoapUtilsTest extends TestCase {
|
||||
|
||||
public void testExtractActionFromContentType() throws Exception {
|
||||
String soapAction = "http://springframework.org/spring-ws/Action";
|
||||
|
||||
String contentType = "application/soap+xml; action=" + soapAction;
|
||||
String result = SoapUtils.extractActionFromContentType(contentType);
|
||||
assertEquals("Invalid SOAP action", soapAction, result);
|
||||
|
||||
contentType = "application/soap+xml; action = " + soapAction;
|
||||
result = SoapUtils.extractActionFromContentType(contentType);
|
||||
assertEquals("Invalid SOAP action", soapAction, result);
|
||||
|
||||
contentType = "application/soap+xml; action=" + soapAction + " ; charset=UTF-8";
|
||||
result = SoapUtils.extractActionFromContentType(contentType);
|
||||
assertEquals("Invalid SOAP action", soapAction, result);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user