SWS-208
This commit is contained in:
@@ -33,6 +33,7 @@ import org.apache.axiom.soap.SOAPFactory;
|
||||
import org.apache.axiom.soap.SOAPMessage;
|
||||
import org.apache.axiom.soap.SOAPProcessingException;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.mime.Attachment;
|
||||
import org.springframework.ws.soap.AbstractSoapMessage;
|
||||
import org.springframework.ws.soap.SoapEnvelope;
|
||||
@@ -74,7 +75,7 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
axiomMessage = axiomFactory.createSOAPMessage(soapEnvelope, soapEnvelope.getBuilder());
|
||||
attachments = new Attachments();
|
||||
payloadCaching = true;
|
||||
soapAction = "";
|
||||
soapAction = "\"\"";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,6 +106,9 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
axiomMessage = soapMessage;
|
||||
axiomFactory = (SOAPFactory) soapMessage.getSOAPEnvelope().getOMFactory();
|
||||
this.attachments = attachments;
|
||||
if (!StringUtils.hasLength(soapAction)) {
|
||||
soapAction = "\"\"";
|
||||
}
|
||||
this.soapAction = soapAction;
|
||||
this.payloadCaching = payloadCaching;
|
||||
}
|
||||
@@ -132,11 +136,15 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
|
||||
|
||||
public void setSoapAction(String soapAction) {
|
||||
if (soapAction == null) {
|
||||
this.soapAction = "";
|
||||
soapAction = "";
|
||||
}
|
||||
else {
|
||||
this.soapAction = soapAction;
|
||||
if (!soapAction.startsWith("\"")) {
|
||||
soapAction = "\"" + soapAction;
|
||||
}
|
||||
if (!soapAction.endsWith("\"")) {
|
||||
soapAction = soapAction + "\"";
|
||||
}
|
||||
this.soapAction = soapAction;
|
||||
}
|
||||
|
||||
public boolean isXopPackage() {
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.support.SaajContentHandler;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.soap.saaj.support.SaajXmlReader;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
import org.springframework.xml.namespace.QNameUtils;
|
||||
import org.xml.sax.InputSource;
|
||||
@@ -284,8 +285,8 @@ public class Saaj11Implementation implements SaajImplementation {
|
||||
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
|
||||
// some SAAJ implementations (Axis 1) do not have a Content-Type header by default
|
||||
MimeHeaders headers = message.getMimeHeaders();
|
||||
if (ObjectUtils.isEmpty(headers.getHeader("Content-Type"))) {
|
||||
headers.addHeader("Content-Type", SoapVersion.SOAP_11.getContentType());
|
||||
if (ObjectUtils.isEmpty(headers.getHeader(TransportConstants.HEADER_CONTENT_TYPE))) {
|
||||
headers.addHeader(TransportConstants.HEADER_CONTENT_TYPE, SoapVersion.SOAP_11.getContentType());
|
||||
if (message.saveRequired()) {
|
||||
message.saveChanges();
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ import javax.xml.transform.dom.DOMSource;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
/**
|
||||
@@ -235,8 +236,8 @@ public class Saaj12Implementation implements SaajImplementation {
|
||||
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
|
||||
// some SAAJ implementations (Axis 1) do not have a Content-Type header by default
|
||||
MimeHeaders headers = message.getMimeHeaders();
|
||||
if (ObjectUtils.isEmpty(headers.getHeader("Content-Type"))) {
|
||||
headers.addHeader("Content-Type", SoapVersion.SOAP_11.getContentType());
|
||||
if (ObjectUtils.isEmpty(headers.getHeader(TransportConstants.HEADER_CONTENT_TYPE))) {
|
||||
headers.addHeader(TransportConstants.HEADER_CONTENT_TYPE, SoapVersion.SOAP_11.getContentType());
|
||||
if (message.saveRequired()) {
|
||||
message.saveChanges();
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ import javax.xml.transform.dom.DOMSource;
|
||||
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportOutputStream;
|
||||
|
||||
/**
|
||||
@@ -262,14 +263,14 @@ public class Saaj13Implementation implements SaajImplementation {
|
||||
TransportOutputStream transportOutputStream = (TransportOutputStream) outputStream;
|
||||
// some SAAJ implementations (Axis 1) do not have a Content-Type header by default
|
||||
MimeHeaders headers = message.getMimeHeaders();
|
||||
if (ObjectUtils.isEmpty(headers.getHeader("Content-Type"))) {
|
||||
if (ObjectUtils.isEmpty(headers.getHeader(TransportConstants.HEADER_CONTENT_TYPE))) {
|
||||
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
|
||||
if (envelope.getElementQName().getNamespaceURI()
|
||||
.equals(SoapVersion.SOAP_11.getEnvelopeNamespaceUri())) {
|
||||
headers.addHeader("Content-Type", SoapVersion.SOAP_11.getContentType());
|
||||
headers.addHeader(TransportConstants.HEADER_CONTENT_TYPE, SoapVersion.SOAP_11.getContentType());
|
||||
}
|
||||
else {
|
||||
headers.addHeader("Content-Type", SoapVersion.SOAP_12.getContentType());
|
||||
headers.addHeader(TransportConstants.HEADER_CONTENT_TYPE, SoapVersion.SOAP_12.getContentType());
|
||||
}
|
||||
if (message.saveRequired()) {
|
||||
message.saveChanges();
|
||||
|
||||
@@ -62,6 +62,10 @@ public class SaajSoapMessage extends AbstractSoapMessage {
|
||||
*/
|
||||
public SaajSoapMessage(SOAPMessage soapMessage) {
|
||||
Assert.notNull(soapMessage, "soapMessage must not be null");
|
||||
MimeHeaders headers = getImplementation().getMimeHeaders(soapMessage);
|
||||
if (ObjectUtils.isEmpty(headers.getHeader(TransportConstants.HEADER_SOAP_ACTION))) {
|
||||
headers.addHeader(TransportConstants.HEADER_SOAP_ACTION, "\"\"");
|
||||
}
|
||||
saajMessage = soapMessage;
|
||||
}
|
||||
|
||||
@@ -92,11 +96,20 @@ 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) ? null : values[0];
|
||||
return ObjectUtils.isEmpty(values) ? "" : values[0];
|
||||
}
|
||||
|
||||
public void setSoapAction(String soapAction) {
|
||||
if (soapAction == null) {
|
||||
soapAction = "";
|
||||
}
|
||||
MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(getSaajMessage());
|
||||
if (!soapAction.startsWith("\"")) {
|
||||
soapAction = "\"" + soapAction;
|
||||
}
|
||||
if (!soapAction.endsWith("\"")) {
|
||||
soapAction = soapAction + "\"";
|
||||
}
|
||||
mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.ws.soap.SoapMessageCreationException;
|
||||
import org.springframework.ws.soap.SoapMessageFactory;
|
||||
import org.springframework.ws.soap.SoapVersion;
|
||||
import org.springframework.ws.soap.saaj.support.SaajUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.ws.transport.TransportInputStream;
|
||||
|
||||
/**
|
||||
@@ -57,8 +58,6 @@ public class SaajSoapMessageFactory implements SoapMessageFactory, InitializingB
|
||||
|
||||
private String messageFactoryProtocol;
|
||||
|
||||
private static final String CONTENT_TYPE = "Content-Type";
|
||||
|
||||
/** Default, empty constructor. */
|
||||
public SaajSoapMessageFactory() {
|
||||
}
|
||||
@@ -166,10 +165,11 @@ public class SaajSoapMessageFactory implements SoapMessageFactory, InitializingB
|
||||
catch (SOAPException ex) {
|
||||
// SAAJ 1.3 RI has a issue with handling multipart XOP content types which contain "startinfo" rather than
|
||||
// "start-info", so let's try and do something about it
|
||||
String contentType = StringUtils.arrayToCommaDelimitedString(mimeHeaders.getHeader(CONTENT_TYPE));
|
||||
String contentType = StringUtils
|
||||
.arrayToCommaDelimitedString(mimeHeaders.getHeader(TransportConstants.HEADER_CONTENT_TYPE));
|
||||
if (contentType.indexOf("startinfo") != -1) {
|
||||
contentType = contentType.replace("startinfo", "start-info");
|
||||
mimeHeaders.setHeader(CONTENT_TYPE, contentType);
|
||||
mimeHeaders.setHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
|
||||
try {
|
||||
return new SaajSoapMessage(messageFactory.createMessage(mimeHeaders, inputStream));
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.ws.transport.TransportConstants;
|
||||
import org.springframework.xml.namespace.QNameUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
@@ -216,8 +217,8 @@ public abstract class SaajUtils {
|
||||
InputStream is = resource.getInputStream();
|
||||
try {
|
||||
MimeHeaders mimeHeaders = new MimeHeaders();
|
||||
mimeHeaders.addHeader("Content-Type", "text/xml");
|
||||
mimeHeaders.addHeader("Content-Length", Long.toString(resource.getFile().length()));
|
||||
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 {
|
||||
|
||||
@@ -45,9 +45,9 @@ public abstract class AbstractSoapMessageTestCase extends AbstractMimeMessageTes
|
||||
}
|
||||
|
||||
public void testSoapAction() throws Exception {
|
||||
String soapAction = "SoapAction";
|
||||
soapMessage.setSoapAction(soapAction);
|
||||
assertEquals("Invalid SOAP Action", soapAction, soapMessage.getSoapAction());
|
||||
assertEquals("Invalid default SOAP Action", "\"\"", soapMessage.getSoapAction());
|
||||
soapMessage.setSoapAction("SoapAction");
|
||||
assertEquals("Invalid SOAP Action", "\"SoapAction\"", soapMessage.getSoapAction());
|
||||
}
|
||||
|
||||
protected abstract Resource[] getSoapSchemas();
|
||||
|
||||
@@ -48,7 +48,7 @@ public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageT
|
||||
String contentType = (String) tos.getHeaders().get("Content-Type");
|
||||
assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_11.getContentType()) != -1);
|
||||
String resultSoapAction = (String) tos.getHeaders().get("SOAPAction");
|
||||
assertEquals("Invalid soap action", soapAction, resultSoapAction);
|
||||
assertEquals("Invalid soap action", "\"" + soapAction + "\"", resultSoapAction);
|
||||
}
|
||||
|
||||
public void testWriteToTransportResponseAttachment() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user