Author: ay
Date: Fri Jun 17 12:36:13 2011
New Revision: 1136860
URL: http://svn.apache.org/viewvc?rev=1136860&view=rev
Log:
[CXF-3597] WS-RM client keeps using an expires source sequence
Added:
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml
(with props)
Modified:
cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java
Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java?rev=1136860&r1=1136859&r2=1136860&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java
(original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java Fri
Jun 17 12:36:13 2011
@@ -303,7 +303,7 @@ public class RMManager implements Server
Source source = getSource(message);
SourceSequence seq = source.getCurrent(inSeqId);
- if (null == seq) {
+ if (null == seq || seq.isExpired()) {
// TODO: better error handling
org.apache.cxf.ws.addressing.EndpointReferenceType to = null;
boolean isServer = RMContextUtils.isServerSide(message);
Modified:
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java?rev=1136860&r1=1136859&r2=1136860&view=diff
==============================================================================
---
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
(original)
+++
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
Fri Jun 17 12:36:13 2011
@@ -60,6 +60,7 @@ import org.apache.cxf.greeter_control.Gr
import org.apache.cxf.greeter_control.GreeterService;
import org.apache.cxf.helpers.XPathUtils;
import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.jaxb.DatatypeFactory;
import org.apache.cxf.jaxws.DispatchImpl;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
@@ -1242,7 +1243,73 @@ public class SequenceTest extends Abstra
mf.verifyLastMessage(new boolean[3], false);
mf.verifyAcknowledgements(new boolean[] {false, true, true}, false);
}
-
+
+ @Test
+ public void testCreateSequenceAfterSequenceExpiration() throws Exception {
+ init("org/apache/cxf/systest/ws/rm/expire-fast-seq.xml", true);
+
+ RMManager manager = greeterBus.getExtension(RMManager.class);
+
+ assertEquals("Unexpected expiration",
DatatypeFactory.createDuration("PT5S"),
+ manager.getSourcePolicy().getSequenceExpiration());
+
+ // phase one
+ greeter.greetMeOneWay("one");
+ greeter.greetMeOneWay("two");
+
+ // let the first sequence expire
+ Thread.sleep(8000);
+
+ // expecting 3 outbounds and 5 or 6 inbounds
+ awaitMessages(3, 5, 5000);
+ MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(),
inRecorder.getInboundMessages());
+
+ // CS, GA, GA
+ mf.verifyMessages(3, true);
+ mf.verifyCreateSequenceAction(0, "PT5S", true);
+
+ String[] expectedActions = new String[]
{RMConstants.getCreateSequenceAction(),
+ GREETMEONEWAY_ACTION,
+ GREETMEONEWAY_ACTION};
+ mf.verifyActions(expectedActions, true);
+ mf.verifyMessageNumbers(new String[] {null, "1", "2"}, true);
+
+ mf.verifyAcknowledgementRange(1, 2);
+
+ // phase two
+
+ outRecorder.getOutboundMessages().clear();
+ inRecorder.getInboundMessages().clear();
+
+ greeter.greetMeOneWay("three");
+
+ // expecting 2 outbounds and 4 inbounds
+ awaitMessages(2, 4, 5000);
+
+ mf = new MessageFlow(outRecorder.getOutboundMessages(),
inRecorder.getInboundMessages());
+
+ // CS, GA
+ mf.verifyMessages(2, true);
+ mf.verifyCreateSequenceAction(0, "PT5S", true);
+
+ expectedActions = new String[] {RMConstants.getCreateSequenceAction(),
+ GREETMEONEWAY_ACTION};
+ mf.verifyActions(expectedActions, true);
+ mf.verifyMessageNumbers(new String[] {null, "1"}, true);
+
+ // PR, CSR, PR, ACK
+ mf.verifyMessages(4, false);
+ mf.purgePartialResponses();
+
+ expectedActions = new String[]
{RMConstants.getCreateSequenceResponseAction(),
+
RMConstants.getSequenceAcknowledgmentAction()};
+ mf.verifyActions(expectedActions, false);
+
+ mf.purge();
+ assertEquals(0, outRecorder.getOutboundMessages().size());
+ assertEquals(0, inRecorder.getInboundMessages().size());
+ }
+
@Test
public void testTerminateOnShutdown() throws Exception {
init("org/apache/cxf/systest/ws/rm/terminate-on-shutdown.xml", true);
Added:
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml?rev=1136860&view=auto
==============================================================================
---
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml
(added)
+++
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml
Fri Jun 17 12:36:13 2011
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:wsrm-mgr="http://cxf.apache.org/ws/rm/manager"
+ xmlns:http="http://cxf.apache.org/transports/http/configuration"
+ xsi:schemaLocation="
+http://cxf.apache.org/ws/rm/manager
http://cxf.apache.org/schemas/configuration/wsrm-manager.xsd
+http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
+
+ <import resource="rminterceptors.xml" />
+
+ <wsrm-mgr:rmManager id="org.apache.cxf.ws.rm.RMManager">
+ <wsrm-mgr:sourcePolicy includeOffer="false" sequenceExpiration
= "PT5S"/>
+ </wsrm-mgr:rmManager>
+
+</beans>
\ No newline at end of file
Propchange:
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml
------------------------------------------------------------------------------
svn:executable = *
Modified:
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java?rev=1136860&r1=1136859&r2=1136860&view=diff
==============================================================================
---
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java
(original)
+++
cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java
Fri Jun 17 12:36:13 2011
@@ -28,6 +28,7 @@ import javax.xml.namespace.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import junit.framework.Assert;
@@ -404,17 +405,18 @@ public class MessageFlow extends Assert
public void verifyMessages(int nExpected, boolean outbound, boolean exact)
{
if (outbound) {
if (exact) {
- assertEquals("Unexpected number of outbound messages" +
outboundDump(),
+ assertEquals("Unexpected number of outbound messages" +
dump(outStreams),
nExpected, outboundMessages.size());
} else {
- assertTrue("Unexpected number of outbound messages: " +
outboundDump(),
+ assertTrue("Unexpected number of outbound messages: " +
dump(outStreams),
nExpected <= outboundMessages.size());
}
} else {
if (exact) {
- assertEquals("Unexpected number of inbound messages",
nExpected, inboundMessages.size());
+ assertEquals("Unexpected number of inbound messages" +
dump(inStreams),
+ nExpected, inboundMessages.size());
} else {
- assertTrue("Unexpected number of inbound messages: " +
inboundMessages.size(),
+ assertTrue("Unexpected number of inbound messages: " +
dump(inStreams),
nExpected <= inboundMessages.size());
}
}
@@ -428,7 +430,7 @@ public class MessageFlow extends Assert
Element e = getRMHeaderElement(doc,
RMConstants.getSequenceAckName());
// let the newer messages take precedence over the older messages
in getting the final range
if (null != e) {
- e = getAcknowledgementRange(e);
+ e = getNamedElement(e, "AcknowledgementRange");
if (null != e) {
currentLower = Long.parseLong(e.getAttribute("Lower"));
currentUpper = Long.parseLong(e.getAttribute("Upper"));
@@ -441,16 +443,40 @@ public class MessageFlow extends Assert
upper, currentUpper);
}
- // note that this method onsiders only the first range element
- private Element getAcknowledgementRange(Element element) throws Exception {
+
+ // note that this method picks the first match and returns
+ private Element getNamedElement(Element element, String lcname) throws
Exception {
for (Node nd = element.getFirstChild(); nd != null; nd =
nd.getNextSibling()) {
- if (Node.ELEMENT_NODE == nd.getNodeType() &&
"AcknowledgementRange".equals(nd.getLocalName())) {
+ if (Node.ELEMENT_NODE == nd.getNodeType() &&
lcname.equals(nd.getLocalName())) {
return (Element)nd;
}
}
return null;
}
+ public void verifyCreateSequenceAction(int index, String expiration,
boolean outbound) throws Exception {
+ Document d = outbound ? outboundMessages.get(index) :
inboundMessages.get(index);
+
+ String expires = getCreateSequenceExpires(d);
+
+ assertEquals("Unexpected expires-value", expiration, expires);
+ }
+
+ private String getCreateSequenceExpires(Document document) throws
Exception {
+ Element envelopeElement = document.getDocumentElement();
+ QName qname = RMConstants.getCreateSequenceOperationName();
+ NodeList nodes =
+ envelopeElement.getElementsByTagNameNS(qname.getNamespaceURI(),
qname.getLocalPart());
+
+ if (nodes.getLength() == 1) {
+ Element element = getNamedElement((Element)nodes.item(0),
"Expires");
+ if (element != null) {
+ return getText(element);
+ }
+ }
+ return null;
+ }
+
public void purgePartialResponses() throws Exception {
for (int i = inboundMessages.size() - 1; i >= 0; i--) {
if (isPartialResponse(inboundMessages.get(i))) {
@@ -507,17 +533,16 @@ public class MessageFlow extends Assert
}
return true;
}
-
-
- private String outboundDump() {
+
+ private String dump(List<byte[]> streams) {
StringBuffer buf = new StringBuffer();
try {
buf.append(System.getProperty("line.separator"));
- for (int i = 0; i < outStreams.size(); i++) {
+ for (int i = 0; i < streams.size(); i++) {
buf.append("[");
buf.append(i);
buf.append("] : ");
- buf.append(new String(outStreams.get(i)));
+ buf.append(new String(streams.get(i)));
buf.append(System.getProperty("line.separator"));
}
} catch (Exception ex) {
@@ -526,7 +551,7 @@ public class MessageFlow extends Assert
return buf.toString();
}
-
+
private String getText(Node node) {
for (Node nd = node.getFirstChild(); nd != null; nd =
nd.getNextSibling()) {
if (Node.TEXT_NODE == nd.getNodeType()) {