diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java index f8a534a3..026c564d 100644 --- a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java +++ b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java @@ -232,13 +232,17 @@ public class AxiomSoapMessage extends AbstractSoapMessage { String charsetEncoding = axiomMessage.getCharsetEncoding(); contentType += "; charset=" + charsetEncoding; } - if (SoapVersion.SOAP_11 == getVersion()) { + SoapVersion version = getVersion(); + if (SoapVersion.SOAP_11 == version) { transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction); + transportOutputStream.addHeader(TransportConstants.HEADER_ACCEPT, version.getContentType()); } - else if (SoapVersion.SOAP_12 == getVersion()) { + else if (SoapVersion.SOAP_12 == version) { contentType += "; action=" + soapAction; + transportOutputStream.addHeader(TransportConstants.HEADER_ACCEPT, version.getContentType()); } transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType); + } if (!(outputFormat.isOptimized()) & outputFormat.isDoingSWA()) { writeSwAMessage(outputStream, outputFormat); diff --git a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessage.java b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessage.java index 1a299035..8ec092f7 100644 --- a/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessage.java +++ b/core/src/main/java/org/springframework/ws/soap/saaj/SaajSoapMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2002-2009 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. @@ -155,6 +155,10 @@ public class SaajSoapMessage extends AbstractSoapMessage { } public void writeTo(OutputStream outputStream) throws IOException { + MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(getSaajMessage()); + if (ObjectUtils.isEmpty(mimeHeaders.getHeader(TransportConstants.HEADER_ACCEPT))) { + mimeHeaders.setHeader(TransportConstants.HEADER_ACCEPT, getVersion().getContentType()); + } try { getImplementation().writeTo(getSaajMessage(), outputStream); outputStream.flush(); diff --git a/core/src/main/java/org/springframework/ws/transport/TransportConstants.java b/core/src/main/java/org/springframework/ws/transport/TransportConstants.java index e452f431..76a9e583 100644 --- a/core/src/main/java/org/springframework/ws/transport/TransportConstants.java +++ b/core/src/main/java/org/springframework/ws/transport/TransportConstants.java @@ -1,5 +1,5 @@ /* - * Copyright 2007 the original author or authors. + * Copyright 2002-2009 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. @@ -24,6 +24,9 @@ package org.springframework.ws.transport; */ public interface TransportConstants { + /** The "Accept" header. */ + String HEADER_ACCEPT = "Accept"; + /** The "Content-Id" header. */ String HEADER_CONTENT_ID = "Content-Id"; @@ -42,8 +45,6 @@ public interface TransportConstants { /** The "action" parameter, used to set SOAP Actions in SOAP 1.2. */ String PARAMETER_ACTION = "action"; - /** - * The empty SOAP action value. - */ + /** The empty SOAP action value. */ String EMPTY_SOAP_ACTION = "\"\""; } diff --git a/core/src/test/java/org/springframework/ws/soap/soap11/AbstractSoap11MessageTestCase.java b/core/src/test/java/org/springframework/ws/soap/soap11/AbstractSoap11MessageTestCase.java index 016a252d..fef8884a 100644 --- a/core/src/test/java/org/springframework/ws/soap/soap11/AbstractSoap11MessageTestCase.java +++ b/core/src/test/java/org/springframework/ws/soap/soap11/AbstractSoap11MessageTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2002-2009 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. @@ -58,6 +58,8 @@ public abstract class AbstractSoap11MessageTestCase extends AbstractSoapMessageT 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); + String resultAccept = (String) tos.getHeaders().get("Accept"); + assertNotNull("Invalid accept header", resultAccept); } public void testWriteToTransportResponseAttachment() throws Exception { diff --git a/core/src/test/java/org/springframework/ws/soap/soap12/AbstractSoap12MessageTestCase.java b/core/src/test/java/org/springframework/ws/soap/soap12/AbstractSoap12MessageTestCase.java index b69245c8..709eb54d 100644 --- a/core/src/test/java/org/springframework/ws/soap/soap12/AbstractSoap12MessageTestCase.java +++ b/core/src/test/java/org/springframework/ws/soap/soap12/AbstractSoap12MessageTestCase.java @@ -1,5 +1,5 @@ /* - * Copyright 2006 the original author or authors. + * Copyright 2002-2009 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. @@ -58,8 +58,11 @@ public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageT result); String contentType = (String) tos.getHeaders().get(TransportConstants.HEADER_CONTENT_TYPE); assertTrue("Invalid Content-Type set", contentType.indexOf(SoapVersion.SOAP_12.getContentType()) != -1); - assertNull(TransportConstants.HEADER_SOAP_ACTION + " header must not be found", tos.getHeaders().get(TransportConstants.HEADER_SOAP_ACTION)); + assertNull(TransportConstants.HEADER_SOAP_ACTION + " header must not be found", + tos.getHeaders().get(TransportConstants.HEADER_SOAP_ACTION)); assertTrue("Invalid Content-Type set", contentType.indexOf(soapAction) != -1); + String resultAccept = (String) tos.getHeaders().get("Accept"); + assertNotNull("Invalid accept header", resultAccept); } public void testWriteToTransportResponseAttachment() throws Exception { @@ -74,5 +77,5 @@ public abstract class AbstractSoap12MessageTestCase extends AbstractSoapMessageT assertTrue("Content-Type for attachment message does not contains type=\"application/soap+xml\"", contentType.indexOf("type=\"application/soap+xml\"") != -1); } - + }