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 2013/04/16 18:54:29 UTC

svn commit: r1468507 - in /cxf/trunk: rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/ rt/ws/rm/src/main/resources/schemas/configuration/ systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/

Author: ay
Date: Tue Apr 16 16:54:28 2013
New Revision: 1468507

URL: http://svn.apache.org/r1468507
Log:
[CXF-4968] Add an option to limit the number of active sequences created at WS-RM endpoints

Added:
    cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/limit-seqs.xml   (with props)
Modified:
    cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Servant.java
    cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager-types.xsd
    cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java

Modified: cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Servant.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Servant.java?rev=1468507&r1=1468506&r2=1468507&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Servant.java (original)
+++ cxf/trunk/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Servant.java Tue Apr 16 16:54:28 2013
@@ -26,7 +26,9 @@ import java.util.logging.Logger;
 
 import javax.xml.datatype.Duration;
 
+import org.apache.cxf.binding.Binding;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxb.DatatypeFactory;
 import org.apache.cxf.message.Exchange;
@@ -75,8 +77,22 @@ public class Servant implements Invoker 
             || RM11Constants.INSTANCE.getCreateSequenceOnewayOperationName().equals(oi.getName())) {
             try {
                 return Collections.singletonList(createSequence(exchange.getInMessage()));
-            } catch (Exception ex) {
-                throw new Fault(ex);
+            } catch (RuntimeException ex) {
+                LOG.log(Level.WARNING, "Sequence creation rejected", ex);
+                SequenceFault sf = 
+                    new SequenceFaultFactory(protocol.getConstants()).createCreateSequenceRefusedFault();
+                Endpoint e = exchange.get(Endpoint.class);
+                Binding b = null == e ? null : e.getBinding();
+                if (null != b) {
+                    RMManager m = reliableEndpoint.getManager();
+                    LOG.fine("Manager: " + m);
+                    BindingFaultFactory bff = m.getBindingFaultFactory(b);
+                    Fault f = bff.createFault(sf, exchange.getInMessage());
+                    // log with warning instead sever, as this may happen for some delayed messages
+                    LogUtils.log(LOG, Level.WARNING, "SEQ_FAULT_MSG", bff.toString(f));
+                    throw f;
+                }
+                throw new Fault(sf);
             }
         } else if (RM10Constants.INSTANCE.getCreateSequenceResponseOnewayOperationName().equals(oi.getName())
             || RM11Constants.INSTANCE.getCreateSequenceResponseOnewayOperationName().equals(oi.getName())) {
@@ -114,6 +130,10 @@ public class Servant implements Invoker 
         createResponse.setIdentifier(destination.generateSequenceIdentifier());
         
         DestinationPolicyType dp = reliableEndpoint.getManager().getDestinationPolicy();
+        if (dp.getMaxSequences() > 0 
+            && destination.getProcessingSequenceCount() >= dp.getMaxSequences()) {
+            throw new RuntimeException("Sequence creation refused");
+        }
         Duration supportedDuration = dp.getSequenceExpiration();
         if (null == supportedDuration) {
             supportedDuration = DatatypeFactory.PT0S;

Modified: cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager-types.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager-types.xsd?rev=1468507&r1=1468506&r2=1468507&view=diff
==============================================================================
--- cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager-types.xsd (original)
+++ cxf/trunk/rt/ws/rm/src/main/resources/schemas/configuration/wsrm-manager-types.xsd Tue Apr 16 16:54:28 2013
@@ -78,6 +78,14 @@
                 </xs:documentation>
             </xs:annotation>      
         </xs:attribute>
+        <xs:attribute name="maxSequences" type="xs:int" use="optional" default="0">
+            <xs:annotation>
+                <xs:documentation>
+                    The maximum number of sequences that can be held active. A value of
+                    0 indicates there is no limit.
+                </xs:documentation>
+            </xs:annotation>      
+        </xs:attribute>
     </xs:complexType>
     
     <xs:complexType name="DestinationPolicyType">
@@ -110,6 +118,14 @@
             </xs:annotation>      
         </xs:attribute>
         
+        <xs:attribute name="maxSequences" type="xs:int" use="optional" default="0">
+            <xs:annotation>
+                <xs:documentation>
+                    The maximum number of sequences that can be held active. A value of
+                    0 indicates there is no limit.
+                </xs:documentation>
+            </xs:annotation>      
+        </xs:attribute>
     </xs:complexType>
 
     <xs:complexType name="SequenceTerminationPolicyType">    

Modified: cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java?rev=1468507&r1=1468506&r2=1468507&view=diff
==============================================================================
--- cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java (original)
+++ cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/SequenceTest.java Tue Apr 16 16:54:28 2013
@@ -1416,6 +1416,37 @@ public class SequenceTest extends Abstra
         mf.verifyAcknowledgements(new boolean[] {false, true}, false);
         
     }    
+
+    @Test
+    public void testCreateSequenceRefused() throws Exception {
+        init("org/apache/cxf/systest/ws/rm/limit-seqs.xml");
+
+        RMManager manager = greeterBus.getExtension(RMManager.class);
+        assertEquals("Unexpected maximum sequence count.", 1, manager.getDestinationPolicy().getMaxSequences());
+
+        greeter.greetMe("one");
+        // force greeter to be re-initialized so that a new sequence is created
+        ClientProxy.getClient(greeter).getConduit().close();
+        initProxy(false, null);
+
+        try {
+            greeter.greetMe("two");
+            fail("Expected fault.");
+        } catch (WebServiceException ex) {
+            // sequence creation refused
+        }   
+        
+        // the third inbound message has a SequenceFault header
+        MessageFlow mf = new MessageFlow(outRecorder.getOutboundMessages(),
+            inRecorder.getInboundMessages(), Names200408.WSA_NAMESPACE_NAME, RM10Constants.NAMESPACE_URI);
+        mf.verifySequenceFault(RM10Constants.CREATE_SEQUENCE_REFUSED_FAULT_QNAME, false, 2);
+        String[] expectedActions = new String[3];
+        expectedActions = new String[] {RM10Constants.CREATE_SEQUENCE_RESPONSE_ACTION,
+                                        GREETME_RESPONSE_ACTION,
+                                        RM10_GENERIC_FAULT_ACTION};
+        mf.verifyActions(expectedActions, false);
+    }
+
     // --- test utilities ---
 
     private void init(String cfgResource) {

Added: cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/limit-seqs.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/limit-seqs.xml?rev=1468507&view=auto
==============================================================================
--- cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/limit-seqs.xml (added)
+++ cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/limit-seqs.xml Tue Apr 16 16:54:28 2013
@@ -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:destinationPolicy maxSequences="1" />
+    </wsrm-mgr:rmManager>
+
+</beans>
\ No newline at end of file

Propchange: cxf/trunk/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/limit-seqs.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml