cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dval...@apache.org
Subject svn commit: r966845 - in /cxf/trunk: rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/ rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/spring/ rt/ws/addr/src/main/resources/schemas/ rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/ syst...
Date Thu, 22 Jul 2010 20:20:36 GMT
Author: dvaleri
Date: Thu Jul 22 20:20:36 2010
New Revision: 966845

URL: http://svn.apache.org/viewvc?rev=966845&view=rev
Log:
[CXF-2906] Added cache abstraction and configuration options for WS-A MessageID caching and
uniqueness enforcement.

Added:
    cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/DefaultMessageIdCache.java
  (with props)
    cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MessageIdCache.java  
(with props)
Modified:
    cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
    cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/WSAddressingFeature.java
    cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/spring/AddressingBeanDefinitionParser.java
    cxf/trunk/rt/ws/addr/src/main/resources/schemas/ws-addr-conf.xsd
    cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/MAPAggregatorTest.java
    cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/WSAFeatureXmlTest.java
    cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/spring.xml

Added: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/DefaultMessageIdCache.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/DefaultMessageIdCache.java?rev=966845&view=auto
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/DefaultMessageIdCache.java
(added)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/DefaultMessageIdCache.java
Thu Jul 22 20:20:36 2010
@@ -0,0 +1,44 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.ws.addressing;
+
+import java.util.Set;
+
+import org.apache.mina.util.ConcurrentHashSet;
+
+/**
+ * An implementation that uses a simple set to store received message IDs.
+ * Note that this implementation does not make any attempt to flush older
+ * message IDs or to persist the message IDs outside of this instance. 
+ */
+public class DefaultMessageIdCache implements MessageIdCache {
+    
+    /**
+     * The set of message IDs.
+     */
+    private final Set<String> messageIdSet = new ConcurrentHashSet<String>();
 
+    
+    public boolean checkUniquenessAndCacheId(String messageId) {
+        return this.messageIdSet.add(messageId);
+    }
+    
+    protected Set<String> getMessageIdSet() {
+        return this.messageIdSet;
+    }
+}

Propchange: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/DefaultMessageIdCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java?rev=966845&r1=966844&r2=966845&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java (original)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MAPAggregator.java Thu
Jul 22 20:20:36 2010
@@ -28,7 +28,6 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -110,11 +109,9 @@ public class MAPAggregator extends Abstr
     };
 
     /**
-     * REVISIT: map usage implies that the *same* interceptor instance 
-     * is used in all chains.
+     * The cache to use for enforcing uniqueness.  Defaults to {@link DefaultMessageIdCache}.
      */
-    protected final Map<String, String> messageIDs = 
-        new ConcurrentHashMap<String, String>();
+    private MessageIdCache messageIdCache = new DefaultMessageIdCache();
     
     private boolean usingAddressingAdvisory = true;
     private boolean addressingRequired;
@@ -185,7 +182,31 @@ public class MAPAggregator extends Abstr
         addressingRequired = required;
     }
     
-    
+    /**
+     * Returns the cache used to enforce duplicate message IDs when
+     * {@link #allowDuplicates()} returns {@code false}.
+     *
+     * @return the cache used to enforce duplicate message IDs
+     */
+    public MessageIdCache getMessageIdCache() {
+        return messageIdCache;
+    }
+
+    /**
+     * Sets the cache used to enforce duplicate message IDs when
+     * {@link #allowDuplicates()} returns {@code false}.
+     *
+     * @param messageIdCache the cache to use
+     *
+     * @throws NullPointerException if {@code messageIdCache} is {@code null}
+     */
+    public void setMessageIdCache(MessageIdCache messageIdCache) {
+        if (messageIdCache == null) {
+            throw new NullPointerException("messageIdCache cannot be null.");
+        }
+        this.messageIdCache = messageIdCache;
+    }
+
     /**
      * Invoked for normal processing of inbound and outbound messages.
      *
@@ -1097,8 +1118,7 @@ public class MAPAggregator extends Abstr
             if (!allowDuplicates) {
                 AttributedURIType messageID = maps.getMessageID();
                 if (messageID != null
-                    && messageIDs.put(messageID.getValue(), 
-                                      messageID.getValue()) != null) {
+                    && !messageIdCache.checkUniquenessAndCacheId(messageID.getValue()))
{
                     LOG.log(Level.WARNING,
                             "DUPLICATE_MESSAGE_ID_MSG",
                             messageID.getValue());

Added: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MessageIdCache.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MessageIdCache.java?rev=966845&view=auto
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MessageIdCache.java (added)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MessageIdCache.java Thu
Jul 22 20:20:36 2010
@@ -0,0 +1,38 @@
+/**
+ * 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.
+ */
+package org.apache.cxf.ws.addressing;
+
+/**
+ * Interface abstracting various ID caches for enforcement of ID uniqueness.
+ */
+public interface MessageIdCache {
+    
+    /**
+     * Check {@code messageId} for uniqueness against previously
+     * encountered values and cache the ID.  Note that the retention
+     * policy for previously encountered values is implementation specific.
+     * 
+     * @param messageId the message ID to check for uniqueness and cache for
+     *                  future comparison
+     *
+     * @return true if and only if {@code messageId} is not already in the
+     *         cache
+     */
+    boolean checkUniquenessAndCacheId(String messageId);
+}

Propchange: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/MessageIdCache.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/WSAddressingFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/WSAddressingFeature.java?rev=966845&r1=966844&r2=966845&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/WSAddressingFeature.java
(original)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/WSAddressingFeature.java
Thu Jul 22 20:20:36 2010
@@ -69,5 +69,25 @@ public class WSAddressingFeature extends
         mapAggregator.setAddressingRequired(required);
     }
     
-    
+    /**
+     * Returns the cache used to enforce duplicate message IDs when
+     * {@link #isAllowDuplicates()} returns {@code false}.
+     *
+     * @return the cache used to enforce duplicate message IDs
+     */
+    public MessageIdCache getMessageIdCache() {
+        return mapAggregator.getMessageIdCache();
+    }
+
+    /**
+     * Sets the cache used to enforce duplicate message IDs when
+     * {@link #isAllowDuplicates()} returns {@code false}.
+     *
+     * @param messageIdCache the cache to use
+     *
+     * @throws NullPointerException if {@code messageIdCache} is {@code null}
+     */
+    public void setMessageIdCache(MessageIdCache messageIdCache) {
+        mapAggregator.setMessageIdCache(messageIdCache);
+    }
 }

Modified: cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/spring/AddressingBeanDefinitionParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/spring/AddressingBeanDefinitionParser.java?rev=966845&r1=966844&r2=966845&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/spring/AddressingBeanDefinitionParser.java
(original)
+++ cxf/trunk/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/spring/AddressingBeanDefinitionParser.java
Thu Jul 22 20:20:36 2010
@@ -20,14 +20,13 @@ package org.apache.cxf.ws.addressing.spr
 
 import org.w3c.dom.Element;
 
+import org.apache.cxf.configuration.spring.AbstractBeanDefinitionParser;
 import org.apache.cxf.ws.addressing.WSAddressingFeature;
-import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
 
-public class AddressingBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
+public class AddressingBeanDefinitionParser extends AbstractBeanDefinitionParser {
 
     @Override
     protected Class getBeanClass(Element arg0) {
         return WSAddressingFeature.class;
     }
-
 }

Modified: cxf/trunk/rt/ws/addr/src/main/resources/schemas/ws-addr-conf.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/main/resources/schemas/ws-addr-conf.xsd?rev=966845&r1=966844&r2=966845&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/main/resources/schemas/ws-addr-conf.xsd (original)
+++ cxf/trunk/rt/ws/addr/src/main/resources/schemas/ws-addr-conf.xsd Thu Jul 22 20:20:36 2010
@@ -30,6 +30,7 @@
            <xs:attribute name="allowDuplicates" type="xs:boolean"/>
            <xs:attribute name="usingAddressingAdvisory" type="xs:boolean"/>
            <xs:attribute name="addressingRequired" type="xs:boolean"/>
+           <xs:attribute name="messageIdCache" type="xs:string"/>
         </xs:complexType>
     </xs:element>
     

Modified: cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/MAPAggregatorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/MAPAggregatorTest.java?rev=966845&r1=966844&r2=966845&view=diff
==============================================================================
--- cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/MAPAggregatorTest.java
(original)
+++ cxf/trunk/rt/ws/addr/src/test/java/org/apache/cxf/ws/addressing/MAPAggregatorTest.java
Thu Jul 22 20:20:36 2010
@@ -253,7 +253,7 @@ public class MAPAggregatorTest extends A
 
     @Test(expected = SoapFault.class)
     public void testResponderInboundInvalidMAPs() throws Exception {
-        aggregator.messageIDs.put("urn:uuid:12345", "urn:uuid:12345");
+        aggregator.getMessageIdCache().checkUniquenessAndCacheId("urn:uuid:12345");
         Message message = setUpMessage(false, false, false, false, false, false, true);
         aggregator.setAllowDuplicates(false);
         aggregator.mediate(message, false);
@@ -263,7 +263,7 @@ public class MAPAggregatorTest extends A
 
     @Test(expected = SoapFault.class)
     public void testResponderInboundInvalidMAPsFault() throws Exception {
-        aggregator.messageIDs.put("urn:uuid:12345", "urn:uuid:12345");
+        aggregator.getMessageIdCache().checkUniquenessAndCacheId("urn:uuid:12345");
         Message message = setUpMessage(false, false, false, false, false, false, true);
         aggregator.setAllowDuplicates(false);
         aggregator.mediate(message, true);
@@ -574,7 +574,8 @@ public class MAPAggregatorTest extends A
                 setUpRebase(message, exchange);
             }
         }
-        if (outbound || aggregator.messageIDs.size() > 0) {
+        if (outbound || ((DefaultMessageIdCache) aggregator.getMessageIdCache())
+            .getMessageIdSet().size() > 0) {
             if (!zeroLengthAction) {
                 Method method = SEI.class.getMethod("op", new Class[0]);
                 setUpMethod(message, exchange, method);

Modified: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/WSAFeatureXmlTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/WSAFeatureXmlTest.java?rev=966845&r1=966844&r2=966845&view=diff
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/WSAFeatureXmlTest.java
(original)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/WSAFeatureXmlTest.java
Thu Jul 22 20:20:36 2010
@@ -34,6 +34,7 @@ import org.apache.cxf.jaxws.JaxWsServerF
 import org.apache.cxf.message.Message;
 import org.apache.cxf.test.AbstractCXFTest;
 import org.apache.cxf.testutil.common.TestUtil;
+import org.apache.cxf.ws.addressing.DefaultMessageIdCache;
 import org.apache.cxf.ws.addressing.MAPAggregator;
 import org.apache.cxf.ws.addressing.soap.MAPCodec;
 import org.apache.hello_world_soap_http.Greeter;
@@ -83,15 +84,22 @@ public class WSAFeatureXmlTest extends A
     private void checkAddressInterceptors(List<Interceptor<? extends Message>>
interceptors) {
         boolean hasAg = false;
         boolean hasCodec = false;
+        Object cache = null;
         
         for (Interceptor<? extends Message> i : interceptors) {
             if (i instanceof MAPAggregator) {
                 hasAg = true;
+                cache = ((MAPAggregator) i).getMessageIdCache();
             } else if (i instanceof MAPCodec) {
                 hasCodec = true;
             }
         }
+        
+        assertTrue(cache instanceof TestCache);
         assertTrue(hasAg);
         assertTrue(hasCodec);
     }
+    
+    public static class TestCache extends DefaultMessageIdCache {
+    }
 }

Modified: cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/spring.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/spring.xml?rev=966845&r1=966844&r2=966845&view=diff
==============================================================================
--- cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/spring.xml
(original)
+++ cxf/trunk/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addressing/spring/spring.xml
Thu Jul 22 20:20:36 2010
@@ -30,14 +30,16 @@ http://www.springframework.org/schema/be
   
   <jaxws:server id="server" abstract="true">
     <jaxws:features>
-      <wsa:addressing allowDuplicates="false"/>
+      <wsa:addressing allowDuplicates="false" messageIdCache="#cache"/>
     </jaxws:features>
   </jaxws:server>
   
   <jaxws:client id="client" abstract="true">
     <jaxws:features>
-      <wsa:addressing allowDuplicates="false"/>
+      <wsa:addressing allowDuplicates="false" messageIdCache="#cache"/>
     </jaxws:features>
   </jaxws:client>  
   
+  <bean id="cache"
+        class="org.apache.cxf.systest.ws.addressing.spring.WSAFeatureXmlTest$TestCache"/>
 </beans>



Mime
View raw message