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.
This commit is contained in:
committed by
Greg L. Turnquist
parent
315eb2b252
commit
e1035a96f0
@@ -48,6 +48,7 @@ import org.springframework.ws.transport.context.TransportContextHolder;
|
||||
* </pre>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509">Web Services Addressing, August 2004</a>
|
||||
* @author Leandro Quiroga
|
||||
* @see <a href="http://www.w3.org/TR/2006/REC-ws-addr-core-20060509">Web Services Addressing, May 2006</a>
|
||||
* @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() {
|
||||
|
||||
@@ -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 <a href="http://www.w3.org/Submission/2004/SUBM-ws-addressing-20040810/">Web Services Addressing, August
|
||||
* 2004</a>
|
||||
* @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() {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
|
||||
<S:Header>
|
||||
<wsa:MessageID>http://example.com/someuniquestring</wsa:MessageID>
|
||||
<wsa:ReplyTo>
|
||||
<wsa:Address>http://example.com/business/client1</wsa:Address>
|
||||
</wsa:ReplyTo>
|
||||
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
|
||||
</S:Header>
|
||||
<S:Body>
|
||||
<f:Delete xmlns:f="http://example.com/fabrikam">
|
||||
<f:maxCount>42</f:maxCount>
|
||||
</f:Delete>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
||||
@@ -2,7 +2,7 @@
|
||||
<env:Header>
|
||||
<wsa:MessageID>uid:1234</wsa:MessageID>
|
||||
<wsa:RelatesTo>http://example.com/someuniquestring</wsa:RelatesTo>
|
||||
<wsa:To env:mustUnderstand="true">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
|
||||
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
|
||||
<wsa:Action>urn:replyAction</wsa:Action>
|
||||
</env:Header>
|
||||
<env:Body/>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<env:Header>
|
||||
<wsa:MessageID>uid:1234</wsa:MessageID>
|
||||
<wsa:RelatesTo>http://example.com/someuniquestring</wsa:RelatesTo>
|
||||
<wsa:To env:mustUnderstand="true">http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
|
||||
<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>
|
||||
<wsa:Action>urn:faultAction</wsa:Action>
|
||||
</env:Header>
|
||||
<env:Body>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<wsa:ReplyTo>
|
||||
<wsa:Address>http://example.com/business/client1</wsa:Address>
|
||||
</wsa:ReplyTo>
|
||||
<wsa:To S:mustUnderstand="true">mailto:fabrikam@example.com</wsa:To>
|
||||
<wsa:To>mailto:fabrikam@example.com</wsa:To>
|
||||
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
|
||||
</S:Header>
|
||||
<S:Body>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"
|
||||
xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
|
||||
<S:Header>
|
||||
<wsa:MessageID>http://example.com/someuniquestring</wsa:MessageID>
|
||||
<wsa:ReplyTo>
|
||||
<wsa:Address>http://example.com/business/client1</wsa:Address>
|
||||
</wsa:ReplyTo>
|
||||
<wsa:To>mailto:fabrikam@example.com</wsa:To>
|
||||
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
|
||||
</S:Header>
|
||||
<S:Body>
|
||||
<f:Delete xmlns:f="http://example.com/fabrikam">
|
||||
<f:maxCount>42</f:maxCount>
|
||||
</f:Delete>
|
||||
</S:Body>
|
||||
</S:Envelope>
|
||||
@@ -3,7 +3,7 @@
|
||||
<env:Header>
|
||||
<wsa:MessageID>uid:1234</wsa:MessageID>
|
||||
<wsa:RelatesTo>uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff</wsa:RelatesTo>
|
||||
<wsa:To env:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>urn:replyAction</wsa:Action>
|
||||
</env:Header>
|
||||
<env:Body/>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<env:Header>
|
||||
<wsa:MessageID>uid:1234</wsa:MessageID>
|
||||
<wsa:RelatesTo>uuid:aaaabbbb-cccc-dddd-eeee-ffffffffffff</wsa:RelatesTo>
|
||||
<wsa:To env:mustUnderstand="true">http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
|
||||
<wsa:Action>urn:faultAction</wsa:Action>
|
||||
</env:Header>
|
||||
<env:Body>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<wsa:ReplyTo>
|
||||
<wsa:Address>http://example.com/business/client1</wsa:Address>
|
||||
</wsa:ReplyTo>
|
||||
<wsa:To S:mustUnderstand="true">mailto:fabrikam@example.com</wsa:To>
|
||||
<wsa:To>mailto:fabrikam@example.com</wsa:To>
|
||||
<wsa:Action>http://example.com/fabrikam/mail/Delete</wsa:Action>
|
||||
</S:Header>
|
||||
<S:Body>
|
||||
|
||||
Reference in New Issue
Block a user