You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ay...@apache.org on 2011/06/17 15:36:20 UTC

svn commit: r1136877 - in /cxf/branches/2.4.x-fixes: ./ rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/ systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/ systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/

Author: ay
Date: Fri Jun 17 13:36:20 2011
New Revision: 1136877

URL: http://svn.apache.org/viewvc?rev=1136877&view=rev
Log:
Merged revisions 1136860 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1136860 | ay | 2011-06-17 14:36:13 +0200 (Fri, 17 Jun 2011) | 1 line
  
  [CXF-3597] WS-RM client keeps using an expires source sequence
........

Added:
    cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml
      - copied unchanged from r1136860, cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/expire-fast-seq.xml
Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java
    cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
    cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun 17 13:36:20 2011
@@ -1 +1 @@
-/cxf/trunk:1134248,1134281,1134523,1135484,1135899,1136380,1136417
+/cxf/trunk:1134248,1134281,1134523,1135484,1135899,1136380,1136417,1136860

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jun 17 13:36:20 2011
@@ -1 +1 @@
-/cxf/trunk:1-1134023,1134142,1134248,1134281,1134523,1135457,1135484,1135899,1136380,1136417
+/cxf/trunk:1-1134023,1134142,1134248,1134281,1134523,1135457,1135484,1135899,1136380,1136417,1136860

Modified: cxf/branches/2.4.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java?rev=1136877&r1=1136876&r2=1136877&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java (original)
+++ cxf/branches/2.4.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMManager.java Fri Jun 17 13:36:20 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/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java?rev=1136877&r1=1136876&r2=1136877&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java (original)
+++ cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java Fri Jun 17 13:36:20 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);

Modified: cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java?rev=1136877&r1=1136876&r2=1136877&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java (original)
+++ cxf/branches/2.4.x-fixes/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/util/MessageFlow.java Fri Jun 17 13:36:20 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()) {