This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.6.x-fixes by this push:
new 9768e1b436a CXF-9276: Keep the exchange of a two-way call for a
partial response … (#3727)
9768e1b436a is described below
commit 9768e1b436a39aa25ca6fdd3f1b32f8a49268347
Author: Freeman(Yue) Fang <[email protected]>
AuthorDate: Tue Nov 17 11:22:54 2026 -0500
CXF-9276: Keep the exchange of a two-way call for a partial response …
(#3727)
* CXF-9276: Keep the exchange of a two-way call for a partial response with
RM headers
With an anonymous AcksTo, a WS-RM destination sends its acknowledgements
in the HTTP response to each request (WS-RM 1.1, section 3.9). With a
decoupled endpoint, the client processes that response as a partial
response, and RMSoapInInterceptor switched the exchange of the call to
the RM protocol endpoint and SequenceAcknowledgement operation, and made
it one-way. The reply, at the decoupled endpoint, was then read against
that operation, so every two-way call failed with
IllegalEmptyResponseException.
For a partial response to an application request, process the RM
headers without updating the exchange.
* CXF-9276: Keep one-way calls as before, and add unit tests
Only a partial response to a two-way request keeps the exchange: for a
one-way call, the exchange is updated as before. Look up the MAPs of the
request without logging a warning if they are missing.
(cherry picked from commit 6300437986c01ff6c3f4783d3ad701b39d25a118)
(cherry picked from commit a589c477ec6b54cf9002b5be1c4224afcdbc8b37)
---
.../apache/cxf/ws/rm/soap/RMSoapInInterceptor.java | 17 +++++
.../cxf/ws/rm/soap/RMSoapInInterceptorTest.java | 73 ++++++++++++++++++++++
.../cxf/systest/ws/rm/ProtocolVariationsTest.java | 49 +++++++++++++++
3 files changed, 139 insertions(+)
diff --git
a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptor.java
b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptor.java
index 1dcdca5abc5..1348cd255f2 100644
--- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptor.java
+++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptor.java
@@ -48,6 +48,7 @@ import org.apache.cxf.interceptor.Interceptor;
import org.apache.cxf.interceptor.InterceptorChain;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.phase.PhaseInterceptor;
import org.apache.cxf.service.Service;
@@ -243,6 +244,15 @@ public class RMSoapInInterceptor extends
AbstractSoapInterceptor {
ProtocolVariation protocol =
ProtocolVariation.findVariant(consts.getWSRMNamespace(),
maps.getNamespaceURI());
+ // A partial response to a two-way application request, e.g. the
acknowledgements for a Sequence
+ // with an anonymous AcksTo while the reply goes to a decoupled
endpoint: the exchange stays with
+ // the application operation, for the reply.
+ if (MessageUtils.isPartialResponse(message) &&
!message.getExchange().isOneWay()
+ && isApplicationRequest(message.getExchange())) {
+ LOG.fine("Partial response to an application request, not updating
service model info");
+ return;
+ }
+
LOG.info("Updating service model info in exchange");
RMManager manager = getManager(message);
@@ -348,6 +358,13 @@ public class RMSoapInInterceptor extends
AbstractSoapInterceptor {
}
}
+ private static boolean isApplicationRequest(Exchange exchange) {
+ Message request = exchange.getOutMessage();
+ AddressingProperties maps = request == null ? null :
ContextUtils.retrieveMAPs(request, false, true, false);
+ return maps != null && maps.getAction() != null
+ &&
!RMContextUtils.isRMProtocolMessage(maps.getAction().getValue());
+ }
+
private RMManager getManager(SoapMessage message) {
InterceptorChain chain = message.getInterceptorChain();
ListIterator<Interceptor<? extends Message>> it = chain.getIterator();
diff --git
a/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptorTest.java
b/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptorTest.java
index 2beb0ccea1f..621370e6aa4 100644
---
a/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptorTest.java
+++
b/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/soap/RMSoapInInterceptorTest.java
@@ -21,6 +21,7 @@ package org.apache.cxf.ws.rm.soap;
import java.io.InputStream;
import java.util.Collection;
+import java.util.List;
import java.util.Set;
import javax.xml.namespace.QName;
@@ -29,14 +30,24 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import org.apache.cxf.BusFactory;
+import org.apache.cxf.binding.soap.SoapFault;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor;
import org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.InterceptorChain;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.service.model.BindingOperationInfo;
import org.apache.cxf.ws.addressing.AddressingProperties;
+import org.apache.cxf.ws.addressing.ContextUtils;
+import org.apache.cxf.ws.rm.AbstractRMInterceptor;
import org.apache.cxf.ws.rm.RM10Constants;
import org.apache.cxf.ws.rm.RMContextUtils;
+import org.apache.cxf.ws.rm.RMException;
+import org.apache.cxf.ws.rm.RMManager;
import org.apache.cxf.ws.rm.RMProperties;
import org.apache.cxf.ws.rm.v200702.AckRequestedType;
import org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement;
@@ -46,9 +57,15 @@ import org.apache.cxf.ws.rm.v200702.SequenceType;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class RMSoapInInterceptorTest {
@@ -156,6 +173,62 @@ public class RMSoapInInterceptorTest {
assertNull(rmps.getAcks());
}
+ @Test
+ public void testPartialResponseToTwoWayRequestKeepsExchange() throws
XMLStreamException {
+ // e.g. the acknowledgements for a Sequence with an anonymous AcksTo,
with a decoupled endpoint
+ SoapMessage message = setUpPartialResponse(false);
+ BindingOperationInfo boi = new BindingOperationInfo();
+ message.getExchange().put(BindingOperationInfo.class, boi);
+ RMSoapInInterceptor codec = new RMSoapInInterceptor();
+ codec.handleMessage(message);
+
+ // the exchange stays with the application operation, for the reply
+ assertSame(boi, message.getExchange().getBindingOperationInfo());
+ assertFalse(message.getExchange().isOneWay());
+ // and the acknowledgements are still decoded
+ RMProperties rmps = RMContextUtils.retrieveRMProperties(message,
false);
+ assertEquals(1, rmps.getAcks().size());
+ }
+
+ @Test
+ public void testPartialResponseToOneWayRequestUpdatesExchange() throws
Exception {
+ SoapMessage message = setUpPartialResponse(true);
+ RMManager manager = mock(RMManager.class);
+ RMException failure = new RMException(new Exception("no reliable
endpoint"));
+ when(manager.getReliableEndpoint(message)).thenThrow(failure);
+ AbstractRMInterceptor<?> rmInterceptor =
mock(AbstractRMInterceptor.class);
+ when(rmInterceptor.getManager()).thenReturn(manager);
+ InterceptorChain chain = mock(InterceptorChain.class);
+ when(chain.getIterator()).thenReturn(List.<Interceptor<? extends
Message>>of(rmInterceptor).listIterator());
+ message.setInterceptorChain(chain);
+ RMSoapInInterceptor codec = new RMSoapInInterceptor();
+ try {
+ codec.handleMessage(message);
+ fail("expected the exchange to be updated with the reliable
endpoint");
+ } catch (SoapFault ex) {
+ assertSame(failure, ex.getCause());
+ }
+ verify(manager).getReliableEndpoint(message);
+ }
+
+ private SoapMessage setUpPartialResponse(boolean oneWay) throws
XMLStreamException {
+ SoapMessage message =
setUpInboundMessage("resources/Acknowledgment2.xml");
+ message.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
+ RMContextUtils.retrieveMAPs(message, false, false)
+
.setAction(ContextUtils.getAttributedURI(RM10Constants.SEQUENCE_ACKNOWLEDGMENT_ACTION));
+
+ Exchange exchange = new ExchangeImpl();
+ exchange.setOneWay(oneWay);
+ Message request = new MessageImpl();
+ request.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
+ AddressingProperties requestMaps = new AddressingProperties();
+
requestMaps.setAction(ContextUtils.getAttributedURI("http://cxf.apache.org/greeter_control/Greeter/greetMe"));
+ RMContextUtils.storeMAPs(requestMaps, request, true, true);
+ exchange.setOutMessage(request);
+ message.setExchange(exchange);
+ return message;
+ }
+
private SoapMessage setUpInboundMessage(String resource) throws
XMLStreamException {
Message message = new MessageImpl();
SoapMessage soapMessage = new SoapMessage(message);
diff --git
a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java
index 5cb31144996..23f4298f5c6 100644
---
a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java
+++
b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java
@@ -387,6 +387,37 @@ public class ProtocolVariationsTest extends
AbstractBusClientServerTestBase {
verifyTwowayNonAnonymous(Names.WSA_NAMESPACE_NAME,
RM11Constants.INSTANCE);
}
+ @Test
+ public void testDefaultDecoupledAnonymousAcksTo() throws Exception {
+ init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", true);
+
+ // the acknowledgements come in the HTTP responses to the requests,
the replies at the decoupled endpoint
+
greeterBus.getExtension(RMManager.class).getSourcePolicy().setAcksTo(Names.WSA_ANONYMOUS_ADDRESS);
+
+ assertEquals("ONE", greeter.greetMe("one"));
+ assertEquals("TWO", greeter.greetMe("two"));
+ assertEquals("THREE", greeter.greetMe("three"));
+
+
verifyTwowayNonAnonymousAnonymousAcksTo(Names200408.WSA_NAMESPACE_NAME,
RM10Constants.INSTANCE);
+ }
+
+ @Test
+ public void testRM11DecoupledAnonymousAcksTo() throws Exception {
+ init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", true);
+
+ // WS-RM 1.1 and WS-A 1.0
+ Client client = ClientProxy.getClient(greeter);
+ client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY,
RM11Constants.NAMESPACE_URI);
+ client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY,
Names.WSA_NAMESPACE_NAME);
+
greeterBus.getExtension(RMManager.class).getSourcePolicy().setAcksTo(Names.WSA_ANONYMOUS_ADDRESS);
+
+ assertEquals("ONE", greeter.greetMe("one"));
+ assertEquals("TWO", greeter.greetMe("two"));
+ assertEquals("THREE", greeter.greetMe("three"));
+
+ verifyTwowayNonAnonymousAnonymousAcksTo(Names.WSA_NAMESPACE_NAME,
RM11Constants.INSTANCE);
+ }
+
@Test
public void testTerminateSequenceDefault() throws Exception {
init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false);
@@ -502,6 +533,24 @@ public class ProtocolVariationsTest extends
AbstractBusClientServerTestBase {
mf.verifyAcknowledgements(new boolean[] {false, true, true, true},
false);
}
+ private void verifyTwowayNonAnonymousAnonymousAcksTo(String wsaUri,
RMConstants consts) throws Exception {
+
+ // CreateSequence and three greetMe messages out;
createSequenceResponse, three greetMeResponse
+ // messages and the acknowledgements of the three greetMe messages (in
their HTTP responses) in
+
+ awaitMessages(4, 7);
+
+ MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(),
+ inRecorder.getInboundMessages(), wsaUri,
consts.getWSRMNamespace());
+
+ mf.verifyMessages(4, true);
+ mf.verifyActions(new String[] {consts.getCreateSequenceAction(),
GREETME_ACTION, GREETME_ACTION,
+ GREETME_ACTION}, true);
+ mf.verifyMessages(7, false);
+ mf.verifyAcknowledgements(3, false, true);
+ mf.verifyAcknowledgementRange(1, 3);
+ }
+
// --- test utilities ---
private void init(String cfgResource, boolean useDecoupledEndpoint) {