Skip to content

Commit e1035a9

Browse files
leaquigregturn
authored andcommitted
Ensure wsa:To is OPTIONAL or REQUIRED per the WS Addressing standard used.
Introduce means to make wsa:To properly handled based on the version of WS Addressing. There are also some faulty assumptions in the test cases that don't properly reflect these two standards. Resolves: #1100. Original pull request: #115.
1 parent 315eb2b commit e1035a9

File tree

15 files changed

+98
-11
lines changed

15 files changed

+98
-11
lines changed

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/client/ActionCallback.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
* </pre>
4949
*
5050
* @author Arjen Poutsma
51+
* @author Leandro Quiroga
5152
* @since 1.0.0
5253
*/
5354
public class ActionCallback implements WebServiceMessageCallback {
@@ -58,6 +59,8 @@ public class ActionCallback implements WebServiceMessageCallback {
5859

5960
private final URI to;
6061

62+
private boolean shouldInitializeTo;
63+
6164
private MessageIdStrategy messageIdStrategy;
6265

6366
private EndpointReference from;
@@ -219,7 +222,7 @@ public void setFaultTo(EndpointReference faultTo) {
219222
* destination was set.
220223
*/
221224
protected URI getTo() {
222-
if (to == null) {
225+
if (to == null && (isToHeaderRequired() || shouldInitializeTo)) {
223226
TransportContext transportContext = TransportContextHolder.getTransportContext();
224227
if (transportContext != null && transportContext.getConnection() != null) {
225228
try {
@@ -234,6 +237,17 @@ protected URI getTo() {
234237
}
235238
}
236239

240+
private boolean isToHeaderRequired() {
241+
return getVersion().isToHeaderRequired();
242+
}
243+
244+
/**
245+
* Set whether to initialize the {@code To} header by default or not.
246+
*/
247+
public void setShouldInitializeTo(boolean shouldInitializeTo) {
248+
this.shouldInitializeTo = shouldInitializeTo;
249+
}
250+
237251
@Override
238252
public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
239253

@@ -244,5 +258,4 @@ public void doWithMessage(WebServiceMessage message) throws IOException, Transfo
244258
getAction(), messageId);
245259
version.addAddressingHeaders(soapMessage, map);
246260
}
247-
248261
}

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AbstractAddressingVersion.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ public void addAddressingHeaders(SoapMessage message, MessageAddressingPropertie
197197
if (map.getTo() != null) {
198198
SoapHeaderElement to = header.addHeaderElement(getToName());
199199
to.setText(map.getTo().toString());
200-
to.setMustUnderstand(true);
201200
}
202201
// From
203202
if (map.getFrom() != null) {

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing10.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
* Communication Foundation (WCF), and supported by Axis 1 and 2.
3131
*
3232
* @author Arjen Poutsma
33-
* @see <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509">Web Services Addressing, August 2004</a>
33+
* @author Leandro Quiroga
34+
* @see <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509">Web Services Addressing, May 2006</a>
3435
* @since 1.5.0
3536
*/
3637

@@ -55,6 +56,11 @@ public boolean hasRequiredProperties(MessageAddressingProperties map) {
5556
return true;
5657

5758
}
59+
60+
@Override
61+
public boolean isToHeaderRequired() {
62+
return false;
63+
}
5864

5965
@Override
6066
protected String getNamespaceUri() {

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/Addressing200408.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
* Microsoft's Web Services Enhancements (WSE) 3.0, and supported by Axis 1 and 2, and XFire.
3131
*
3232
* @author Arjen Poutsma
33+
* @author Leandro Quiroga
3334
* @see <a href="http://www.w3.org/Submission/2004/SUBM-ws-addressing-20040810/">Web Services Addressing, August
3435
* 2004</a>
3536
* @since 1.5.0
@@ -58,6 +59,11 @@ public boolean hasRequiredProperties(MessageAddressingProperties map) {
5859
}
5960
return true;
6061
}
62+
63+
@Override
64+
public boolean isToHeaderRequired() {
65+
return true;
66+
}
6167

6268
@Override
6369
protected final URI getAnonymous() {

spring-ws-core/src/main/java/org/springframework/ws/soap/addressing/version/AddressingVersion.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* Defines the contract for a specific version of the WS-Addressing specification.
2727
*
2828
* @author Arjen Poutsma
29+
* @author Leandro Quiroga
2930
* @since 1.5.0
3031
*/
3132
public interface AddressingVersion {
@@ -63,6 +64,14 @@ public interface AddressingVersion {
6364
*/
6465
boolean hasRequiredProperties(MessageAddressingProperties map);
6566

67+
68+
/**
69+
* Indicates whether the wsa:To header is REQUIRED or not.
70+
*
71+
* @return {@code true} if the wsa:To header of the {@link AddressingVersion} is REQUIRED.
72+
*/
73+
boolean isToHeaderRequired();
74+
6675
/*
6776
* Address URIs
6877
*/

spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/AbstractWsAddressingTestCase.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public abstract class AbstractWsAddressingTestCase {
3838
@BeforeEach
3939
public void createMessageFactory() throws Exception {
4040
messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
41+
XMLUnit.setIgnoreWhitespace(true);
4142
}
4243

4344
protected SaajSoapMessage loadSaajMessage(String fileName) throws SOAPException, IOException {

spring-ws-core/src/test/java/org/springframework/ws/soap/addressing/client/AbstractActionCallbackTestCase.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public void testDefaults() throws Exception {
9393
URI connectionUri = new URI("mailto:[email protected]");
9494
callback = new ActionCallback(action, getVersion());
9595
callback.setMessageIdStrategy(strategyMock);
96+
callback.setShouldInitializeTo(true);
9697
expect(connectionMock.getUri()).andReturn(connectionUri);
9798

9899
SaajSoapMessage message = createDeleteMessage();
@@ -109,13 +110,35 @@ public void testDefaults() throws Exception {
109110

110111
verify(strategyMock, connectionMock);
111112
}
113+
114+
@Test
115+
public void testNotInitializeTo() throws Exception {
116+
URI action = new URI("http://example.com/fabrikam/mail/Delete");
117+
URI connectionUri = new URI("mailto:[email protected]");
118+
callback = new ActionCallback(action, getVersion());
119+
callback.setMessageIdStrategy(strategyMock);
120+
expect(connectionMock.getUri()).andReturn(connectionUri).times(0, 1);
121+
122+
SaajSoapMessage message = createDeleteMessage();
123+
expect(strategyMock.newMessageId(message)).andReturn(new URI("http://example.com/someuniquestring"));
124+
callback.setReplyTo(new EndpointReference(new URI("http://example.com/business/client1")));
125+
126+
replay(strategyMock, connectionMock);
127+
128+
callback.doWithMessage(message);
129+
130+
SaajSoapMessage expected = loadSaajMessage(getTestPath() + "/request-without-shouldInitializeTo.xml");
131+
assertXMLSimilar(expected, message);
132+
verify(strategyMock, connectionMock);
133+
}
134+
112135

113136
private SaajSoapMessage createDeleteMessage() throws SOAPException {
114137

115138
SOAPMessage saajMessage = messageFactory.createMessage();
116139
SOAPBody saajBody = saajMessage.getSOAPBody();
117140
SOAPBodyElement delete = saajBody.addBodyElement(new QName("http://example.com/fabrikam", "Delete"));
118-
SOAPElement maxCount = delete.addChildElement(new QName("maxCount"));
141+
SOAPElement maxCount = delete.addChildElement(new QName("http://example.com/fabrikam", "maxCount"));
119142
maxCount.setTextContent("42");
120143
return new SaajSoapMessage(saajMessage);
121144
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
2+
<S:Header>
3+
<wsa:MessageID>http://example.com/someuniquestring</wsa:MessageID>
4+
<wsa:ReplyTo>
5+
<wsa:Address>http://example.com/business/client1</wsa:Address>
6+
</wsa:ReplyTo>
7+
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
8+
</S:Header>
9+
<S:Body>
10+
<f:Delete xmlns:f="http://example.com/fabrikam">
11+
<f:maxCount>42</f:maxCount>
12+
</f:Delete>
13+
</S:Body>
14+
</S:Envelope>

spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-anonymous.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<env:Header>
33
<wsa:MessageID>uid:1234</wsa:MessageID>
44
<wsa:RelatesTo>http://example.com/someuniquestring</wsa:RelatesTo>
5-
<wsa:To env:mustUnderstand="true">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
5+
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
66
<wsa:Action>urn:replyAction</wsa:Action>
77
</env:Header>
88
<env:Body/>

spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/response-fault-to.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<env:Header>
33
<wsa:MessageID>uid:1234</wsa:MessageID>
44
<wsa:RelatesTo>http://example.com/someuniquestring</wsa:RelatesTo>
5-
<wsa:To env:mustUnderstand="true">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
5+
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
66
<wsa:Action>urn:faultAction</wsa:Action>
77
</env:Header>
88
<env:Body>

spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/10/valid.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<wsa:ReplyTo>
55
<wsa:Address>http://example.com/business/client1</wsa:Address>
66
</wsa:ReplyTo>
7-
<wsa:To S:mustUnderstand="true">mailto:[email protected]</wsa:To>
7+
<wsa:To>mailto:[email protected]</wsa:To>
88
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
99
</S:Header>
1010
<S:Body>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"
2+
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
3+
<S:Header>
4+
<wsa:MessageID>http://example.com/someuniquestring</wsa:MessageID>
5+
<wsa:ReplyTo>
6+
<wsa:Address>http://example.com/business/client1</wsa:Address>
7+
</wsa:ReplyTo>
8+
<wsa:To>mailto:[email protected]</wsa:To>
9+
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
10+
</S:Header>
11+
<S:Body>
12+
<f:Delete xmlns:f="http://example.com/fabrikam">
13+
<f:maxCount>42</f:maxCount>
14+
</f:Delete>
15+
</S:Body>
16+
</S:Envelope>

spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-anonymous.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<env:Header>
44
<wsa:MessageID>uid:1234</wsa:MessageID>
55
<wsa:RelatesTo>uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff</wsa:RelatesTo>
6-
<wsa:To env:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
6+
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
77
<wsa:Action>urn:replyAction</wsa:Action>
88
</env:Header>
99
<env:Body/>

spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/response-fault-to.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<env:Header>
44
<wsa:MessageID>uid:1234</wsa:MessageID>
55
<wsa:RelatesTo>uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff</wsa:RelatesTo>
6-
<wsa:To env:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
6+
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
77
<wsa:Action>urn:faultAction</wsa:Action>
88
</env:Header>
99
<env:Body>

spring-ws-core/src/test/resources/org/springframework/ws/soap/addressing/200408/valid.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<wsa:ReplyTo>
66
<wsa:Address>http://example.com/business/client1</wsa:Address>
77
</wsa:ReplyTo>
8-
<wsa:To S:mustUnderstand="true">mailto:[email protected]</wsa:To>
8+
<wsa:To>mailto:[email protected]</wsa:To>
99
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
1010
</S:Header>
1111
<S:Body>

0 commit comments

Comments
 (0)