diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/client/ActionCallback.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/client/ActionCallback.java
index 07f159a7..b8125658 100644
--- a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/client/ActionCallback.java
+++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/client/ActionCallback.java
@@ -48,6 +48,7 @@ import org.springframework.ws.transport.context.TransportContextHolder;
*
*
* @author Arjen Poutsma
+ * @author Leandro Quiroga
* @since 1.0.0
*/
public class ActionCallback implements WebServiceMessageCallback {
@@ -58,6 +59,8 @@ public class ActionCallback implements WebServiceMessageCallback {
private final URI to;
+ private boolean shouldInitializeTo;
+
private MessageIdStrategy messageIdStrategy;
private EndpointReference from;
@@ -219,7 +222,7 @@ public class ActionCallback implements WebServiceMessageCallback {
* destination was set.
*/
protected URI getTo() {
- if (to == null) {
+ if (to == null && (isToHeaderRequired() || shouldInitializeTo)) {
TransportContext transportContext = TransportContextHolder.getTransportContext();
if (transportContext != null && transportContext.getConnection() != null) {
try {
@@ -234,6 +237,17 @@ public class ActionCallback implements WebServiceMessageCallback {
}
}
+ private boolean isToHeaderRequired() {
+ return getVersion().isToHeaderRequired();
+ }
+
+ /**
+ * Set whether to initialize the {@code To} header by default or not.
+ */
+ public void setShouldInitializeTo(boolean shouldInitializeTo) {
+ this.shouldInitializeTo = shouldInitializeTo;
+ }
+
@Override
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
@@ -244,5 +258,4 @@ public class ActionCallback implements WebServiceMessageCallback {
getAction(), messageId);
version.addAddressingHeaders(soapMessage, map);
}
-
}
diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AbstractAddressingVersion.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AbstractAddressingVersion.java
index d3fd8166..754c45b3 100644
--- a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AbstractAddressingVersion.java
+++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AbstractAddressingVersion.java
@@ -197,7 +197,6 @@ public abstract class AbstractAddressingVersion extends TransformerObjectSupport
if (map.getTo() != null) {
SoapHeaderElement to = header.addHeaderElement(getToName());
to.setText(map.getTo().toString());
- to.setMustUnderstand(true);
}
// From
if (map.getFrom() != null) {
diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing10.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing10.java
index b4a58a69..e97efe84 100644
--- a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing10.java
+++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing10.java
@@ -30,7 +30,8 @@ import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
* Communication Foundation (WCF), and supported by Axis 1 and 2.
*
* @author Arjen Poutsma
- * @see Web Services Addressing, August 2004
+ * @author Leandro Quiroga
+ * @see Web Services Addressing, May 2006
* @since 1.5.0
*/
@@ -55,6 +56,11 @@ public class Addressing10 extends AbstractAddressingVersion {
return true;
}
+
+ @Override
+ public boolean isToHeaderRequired() {
+ return false;
+ }
@Override
protected String getNamespaceUri() {
diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing200408.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing200408.java
index 9fa582a9..f68865e6 100644
--- a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing200408.java
+++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing200408.java
@@ -30,6 +30,7 @@ import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
* Microsoft's Web Services Enhancements (WSE) 3.0, and supported by Axis 1 and 2, and XFire.
*
* @author Arjen Poutsma
+ * @author Leandro Quiroga
* @see Web Services Addressing, August
* 2004
* @since 1.5.0
@@ -58,6 +59,11 @@ public class Addressing200408 extends AbstractAddressingVersion {
}
return true;
}
+
+ @Override
+ public boolean isToHeaderRequired() {
+ return true;
+ }
@Override
protected final URI getAnonymous() {
diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AddressingVersion.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AddressingVersion.java
index 67c10fd5..244d2763 100644
--- a/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AddressingVersion.java
+++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AddressingVersion.java
@@ -26,6 +26,7 @@ import org.springframework.ws.soap.addressing.core.MessageAddressingProperties;
* Defines the contract for a specific version of the WS-Addressing specification.
*
* @author Arjen Poutsma
+ * @author Leandro Quiroga
* @since 1.5.0
*/
public interface AddressingVersion {
@@ -63,6 +64,14 @@ public interface AddressingVersion {
*/
boolean hasRequiredProperties(MessageAddressingProperties map);
+
+ /**
+ * Indicates whether the wsa:To header is REQUIRED or not.
+ *
+ * @return {@code true} if the wsa:To header of the {@link AddressingVersion} is REQUIRED.
+ */
+ boolean isToHeaderRequired();
+
/*
* Address URIs
*/
diff --git a/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/AbstractWsAddressingTestCase.java b/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/AbstractWsAddressingTestCase.java
index 4e0874d0..d1c2d469 100644
--- a/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/AbstractWsAddressingTestCase.java
+++ b/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/AbstractWsAddressingTestCase.java
@@ -38,6 +38,7 @@ public abstract class AbstractWsAddressingTestCase {
@BeforeEach
public void createMessageFactory() throws Exception {
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
+ XMLUnit.setIgnoreWhitespace(true);
}
protected SaajSoapMessage loadSaajMessage(String fileName) throws SOAPException, IOException {
diff --git a/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/client/AbstractActionCallbackTestCase.java b/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/client/AbstractActionCallbackTestCase.java
index 61159c0f..a400ffac 100644
--- a/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/client/AbstractActionCallbackTestCase.java
+++ b/spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/client/AbstractActionCallbackTestCase.java
@@ -93,6 +93,7 @@ public abstract class AbstractActionCallbackTestCase extends AbstractWsAddressin
URI connectionUri = new URI("mailto:fabrikam@example.com");
callback = new ActionCallback(action, getVersion());
callback.setMessageIdStrategy(strategyMock);
+ callback.setShouldInitializeTo(true);
expect(connectionMock.getUri()).andReturn(connectionUri);
SaajSoapMessage message = createDeleteMessage();
@@ -109,13 +110,35 @@ public abstract class AbstractActionCallbackTestCase extends AbstractWsAddressin
verify(strategyMock, connectionMock);
}
+
+ @Test
+ public void testNotInitializeTo() throws Exception {
+ URI action = new URI("http://example.com/fabrikam/mail/Delete");
+ URI connectionUri = new URI("mailto:fabrikam@example.com");
+ callback = new ActionCallback(action, getVersion());
+ callback.setMessageIdStrategy(strategyMock);
+ expect(connectionMock.getUri()).andReturn(connectionUri).times(0, 1);
+
+ SaajSoapMessage message = createDeleteMessage();
+ expect(strategyMock.newMessageId(message)).andReturn(new URI("http://example.com/someuniquestring"));
+ callback.setReplyTo(new EndpointReference(new URI("http://example.com/business/client1")));
+
+ replay(strategyMock, connectionMock);
+
+ callback.doWithMessage(message);
+
+ SaajSoapMessage expected = loadSaajMessage(getTestPath() + "/request-without-shouldInitializeTo.xml");
+ assertXMLSimilar(expected, message);
+ verify(strategyMock, connectionMock);
+ }
+
private SaajSoapMessage createDeleteMessage() throws SOAPException {
SOAPMessage saajMessage = messageFactory.createMessage();
SOAPBody saajBody = saajMessage.getSOAPBody();
SOAPBodyElement delete = saajBody.addBodyElement(new QName("http://example.com/fabrikam", "Delete"));
- SOAPElement maxCount = delete.addChildElement(new QName("maxCount"));
+ SOAPElement maxCount = delete.addChildElement(new QName("http://example.com/fabrikam", "maxCount"));
maxCount.setTextContent("42");
return new SaajSoapMessage(saajMessage);
}
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/request-without-shouldInitializeTo.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/request-without-shouldInitializeTo.xml
new file mode 100644
index 00000000..e9f8edbe
--- /dev/null
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/request-without-shouldInitializeTo.xml
@@ -0,0 +1,14 @@
+
+
+ http://example.com/someuniquestring
+
+ http://example.com/business/client1
+
+ http://example.com/fabrikam/mail/Delete
+
+
+
+ 42
+
+
+
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-anonymous.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-anonymous.xml
index 2ba12041..8304cab4 100644
--- a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-anonymous.xml
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-anonymous.xml
@@ -2,7 +2,7 @@
uid:1234
http://example.com/someuniquestring
- http://www.w3.org/2005/08/addressing/anonymous
+ http://www.w3.org/2005/08/addressing/anonymous
urn:replyAction
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-fault-to.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-fault-to.xml
index 4e0392db..5a7af625 100644
--- a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-fault-to.xml
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-fault-to.xml
@@ -2,7 +2,7 @@
uid:1234
http://example.com/someuniquestring
- http://www.w3.org/2005/08/addressing/anonymous
+ http://www.w3.org/2005/08/addressing/anonymous
urn:faultAction
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/valid.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/valid.xml
index e44c1df8..5ac63f7a 100644
--- a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/valid.xml
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/valid.xml
@@ -4,7 +4,7 @@
http://example.com/business/client1
- mailto:fabrikam@example.com
+ mailto:fabrikam@example.com
http://example.com/fabrikam/mail/Delete
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/request-without-shouldInitializeTo.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/request-without-shouldInitializeTo.xml
new file mode 100644
index 00000000..ee2bac92
--- /dev/null
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/request-without-shouldInitializeTo.xml
@@ -0,0 +1,16 @@
+
+
+ http://example.com/someuniquestring
+
+ http://example.com/business/client1
+
+ mailto:fabrikam@example.com
+ http://example.com/fabrikam/mail/Delete
+
+
+
+ 42
+
+
+
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-anonymous.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-anonymous.xml
index 99276263..3789a2a8 100644
--- a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-anonymous.xml
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-anonymous.xml
@@ -3,7 +3,7 @@
uid:1234
uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff
- http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
urn:replyAction
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-fault-to.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-fault-to.xml
index 4751eb0e..24f6644e 100644
--- a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-fault-to.xml
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-fault-to.xml
@@ -3,7 +3,7 @@
uid:1234
uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff
- http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
+ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous
urn:faultAction
diff --git a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/valid.xml b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/valid.xml
index fb813b6e..ee2bac92 100644
--- a/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/valid.xml
+++ b/spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/valid.xml
@@ -5,7 +5,7 @@
http://example.com/business/client1
- mailto:fabrikam@example.com
+ mailto:fabrikam@example.com
http://example.com/fabrikam/mail/Delete