You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2014/06/30 19:28:15 UTC

[1/4] git commit: Recording .gitmergeinfo Changes

Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes a25efba08 -> 0a0b9deec


Recording .gitmergeinfo Changes


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4031f537
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4031f537
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4031f537

Branch: refs/heads/2.7.x-fixes
Commit: 4031f53706247231e2b70244932fe1b6f5042444
Parents: 3537716
Author: Daniel Kulp <dk...@apache.org>
Authored: Mon Jun 30 13:17:06 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Mon Jun 30 13:17:06 2014 -0400

----------------------------------------------------------------------
 .gitmergeinfo | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/4031f537/.gitmergeinfo
----------------------------------------------------------------------
diff --git a/.gitmergeinfo b/.gitmergeinfo
index 5948d58..badac7a 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -1669,6 +1669,7 @@ M eb4e91ab9d3e29cc1ed35f61848a0a7ae3c917b8
 M ebbb056a41136e2de99ac5219cf69d5c3e579125
 M ebc3eb2a445616c137e998eec7b00cb084332092
 M ebd2889e35dddb29935436e0bc3b8b2560b9e23f
+M ec4d58227e5999ba668fd23e79f677dccd73bc94
 M ec7720ebed702684d3cd4b47e95f6cc1a81a6983
 M ec8393ef9cfde228430def55a185914ba07d8024
 M ec8538e7c5db62ff475bb5ab9e517040e1a4655f


[2/4] git commit: [CXF-5802] Fix a condition introduced with the removeCache call where if two proxies are using the same cache, closing one (or having it GC'd) would cause the cache to become invalid.

Posted by dk...@apache.org.
[CXF-5802] Fix a condition introduced with the removeCache call where if two proxies are using the same cache, closing one (or having it GC'd) would cause the cache to become invalid.

Conflicts:
	rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
	systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/35377167
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/35377167
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/35377167

Branch: refs/heads/2.7.x-fixes
Commit: 353771670f917714c8370a5bf45c298649622c69
Parents: a25efba
Author: Daniel Kulp <dk...@apache.org>
Authored: Mon Jun 30 12:29:00 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Mon Jun 30 13:17:06 2014 -0400

----------------------------------------------------------------------
 .../security/tokenstore/EHCacheTokenStore.java  | 42 ++++++++++++++++++--
 .../cxf/systest/ws/cache/CachingTest.java       | 38 +++++++++++-------
 2 files changed, 62 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/35377167/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
index 3ee6c84..4270934 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
@@ -26,11 +26,13 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Ehcache;
 import net.sf.ehcache.Element;
+import net.sf.ehcache.Status;
 import net.sf.ehcache.config.CacheConfiguration;
 
 import org.apache.cxf.Bus;
@@ -44,7 +46,6 @@ import org.apache.cxf.ws.security.cache.EHCacheManagerHolder;
  * and the max TTL is 12 hours.
  */
 public class EHCacheTokenStore implements TokenStore, Closeable, BusLifeCycleListener {
-
     public static final long DEFAULT_TTL = 3600L;
     public static final long MAX_TTL = DEFAULT_TTL * 12L;
     
@@ -64,13 +65,34 @@ public class EHCacheTokenStore implements TokenStore, Closeable, BusLifeCycleLis
         CacheConfiguration cc = EHCacheManagerHolder.getCacheConfiguration(key, cacheManager)
             .overflowToDisk(false); //tokens not writable
         
-        Ehcache newCache = new Cache(cc);
+        Cache newCache = new RefCountCache(cc);
         cache = cacheManager.addCacheIfAbsent(newCache);
+        synchronized (cache) {
+            if (cache.getStatus() != Status.STATUS_ALIVE) {
+                cache = cacheManager.addCacheIfAbsent(newCache);
+            }
+            if (cache instanceof RefCountCache) {
+                ((RefCountCache)cache).incrementAndGet();
+            }
+        }
         
         // Set the TimeToLive value from the CacheConfiguration
         ttl = cc.getTimeToLiveSeconds();
     }
     
+    private static class RefCountCache extends Cache {
+        AtomicInteger count = new AtomicInteger();
+        public RefCountCache(CacheConfiguration cc) {
+            super(cc);
+        }
+        public int incrementAndGet() {
+            return count.incrementAndGet();
+        }
+        public int decrementAndGet() {
+            return count.decrementAndGet();
+        }
+    }
+    
     /**
      * Set a new (default) TTL value in seconds
      * @param newTtl a new (default) TTL value in seconds
@@ -114,13 +136,16 @@ public class EHCacheTokenStore implements TokenStore, Closeable, BusLifeCycleLis
     }
     
     public void remove(String identifier) {
-        if (!StringUtils.isEmpty(identifier) && cache.isKeyInCache(identifier)) {
+        if (cache != null && !StringUtils.isEmpty(identifier) && cache.isKeyInCache(identifier)) {
             cache.remove(identifier);
         }
     }
 
     @SuppressWarnings("unchecked")
     public Collection<String> getTokenIdentifiers() {
+        if (cache == null) {
+            return null;
+        }
         return cache.getKeysWithExpiryCheck();
     }
     
@@ -138,6 +163,9 @@ public class EHCacheTokenStore implements TokenStore, Closeable, BusLifeCycleLis
     }
     
     public SecurityToken getToken(String identifier) {
+        if (cache == null) {
+            return null;
+        }
         Element element = cache.get(identifier);
         if (element != null && !cache.isExpired(element)) {
             return (SecurityToken)element.getObjectValue();
@@ -179,7 +207,13 @@ public class EHCacheTokenStore implements TokenStore, Closeable, BusLifeCycleLis
         if (cacheManager != null) {
             // this step is especially important for global shared cache manager
             if (cache != null) {
-                cacheManager.removeCache(cache.getName());
+                synchronized (cache) {
+                    if (cache instanceof RefCountCache) {
+                        if (((RefCountCache)cache).decrementAndGet() == 0) {
+                            cacheManager.removeCache(cache.getName());
+                        }
+                    }
+                }                
             }
             
             EHCacheManagerHolder.releaseCacheManger(cacheManager);

http://git-wip-us.apache.org/repos/asf/cxf/blob/35377167/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
index c324e07..d3c73e8 100644
--- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
@@ -90,24 +90,32 @@ public class CachingTest extends AbstractBusClientServerTestBase {
             );
         assertNotNull(tokenStore);
         // We expect 1 token
-        assertEquals(tokenStore.getTokenIdentifiers().size(), 1);
+        assertEquals(1, tokenStore.getTokenIdentifiers().size());
+        
+        
         
         // Second invocation
-        port = service.getPort(portQName, DoubleItPortType.class);
-        updateAddressPort(port, PORT);
+        DoubleItPortType port2 = service.getPort(portQName, DoubleItPortType.class);
+        updateAddressPort(port2, test.getPort());
         
-        port.doubleIt(35);
+        port2.doubleIt(35);
 
-        client = ClientProxy.getClient(port);
+        client = ClientProxy.getClient(port2);
         tokenStore = 
             (TokenStore)client.getEndpoint().getEndpointInfo().getProperty(
                 SecurityConstants.TOKEN_STORE_CACHE_INSTANCE
             );
+
         assertNotNull(tokenStore);
         // There should now be 2 tokens as both proxies share the same TokenStore
-        assertEquals(tokenStore.getTokenIdentifiers().size(), 2);
+        assertEquals(2, tokenStore.getTokenIdentifiers().size());
         
         ((java.io.Closeable)port).close();
+        //port2 is still holding onto the cache, thus, this should still be 4
+        assertEquals(4, tokenStore.getTokenIdentifiers().size());       
+        ((java.io.Closeable)port2).close();
+        //port2 is now closed, this should be null
+        assertNull(tokenStore.getTokenIdentifiers());       
         bus.shutdown(true);
     }
     
@@ -146,31 +154,33 @@ public class CachingTest extends AbstractBusClientServerTestBase {
             );
         assertNotNull(tokenStore);
         // We expect 1 token
-        assertEquals(tokenStore.getTokenIdentifiers().size(), 1);
+        assertEquals(1, tokenStore.getTokenIdentifiers().size());
+        
         
         // Second invocation
-        port = service.getPort(portQName, DoubleItPortType.class);
-        updateAddressPort(port, PORT);
+        DoubleItPortType port2 = service.getPort(portQName, DoubleItPortType.class);
+        updateAddressPort(port2, test.getPort());
         
-        ((BindingProvider)port).getRequestContext().put(
+        ((BindingProvider)port2).getRequestContext().put(
             SecurityConstants.CACHE_IDENTIFIER, "proxy2"
         );
-        ((BindingProvider)port).getRequestContext().put(
+        ((BindingProvider)port2).getRequestContext().put(
             SecurityConstants.CACHE_CONFIG_FILE, "client/per-proxy-cache.xml"
         );
         
-        port.doubleIt(35);
+        port2.doubleIt(35);
 
-        client = ClientProxy.getClient(port);
+        client = ClientProxy.getClient(port2);
         tokenStore = 
             (TokenStore)client.getEndpoint().getEndpointInfo().getProperty(
                 SecurityConstants.TOKEN_STORE_CACHE_INSTANCE
             );
         assertNotNull(tokenStore);
         // We expect 1 token
-        assertEquals(tokenStore.getTokenIdentifiers().size(), 1);
+        assertEquals(1, tokenStore.getTokenIdentifiers().size());
         
         ((java.io.Closeable)port).close();
+        ((java.io.Closeable)port2).close();
         bus.shutdown(true);
     }
     


[3/4] git commit: Fix PMD issue

Posted by dk...@apache.org.
Fix PMD issue


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c518d5b2
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c518d5b2
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c518d5b2

Branch: refs/heads/2.7.x-fixes
Commit: c518d5b2130edca8b79e1b0cd9cb05cee382d77d
Parents: 4031f53
Author: Daniel Kulp <dk...@apache.org>
Authored: Mon Jun 30 13:16:35 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Mon Jun 30 13:17:18 2014 -0400

----------------------------------------------------------------------
 .../apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java  | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c518d5b2/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
index 4270934..d6b59ee 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/tokenstore/EHCacheTokenStore.java
@@ -208,10 +208,9 @@ public class EHCacheTokenStore implements TokenStore, Closeable, BusLifeCycleLis
             // this step is especially important for global shared cache manager
             if (cache != null) {
                 synchronized (cache) {
-                    if (cache instanceof RefCountCache) {
-                        if (((RefCountCache)cache).decrementAndGet() == 0) {
-                            cacheManager.removeCache(cache.getName());
-                        }
+                    if (cache instanceof RefCountCache
+                        && ((RefCountCache)cache).decrementAndGet() == 0) {
+                        cacheManager.removeCache(cache.getName());
                     }
                 }                
             }


[4/4] git commit: Fix compile failure

Posted by dk...@apache.org.
Fix compile failure


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/0a0b9dee
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/0a0b9dee
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/0a0b9dee

Branch: refs/heads/2.7.x-fixes
Commit: 0a0b9deec75db92a58ed6743b91efc4d3870fea7
Parents: c518d5b
Author: Daniel Kulp <dk...@apache.org>
Authored: Mon Jun 30 13:27:44 2014 -0400
Committer: Daniel Kulp <dk...@apache.org>
Committed: Mon Jun 30 13:27:44 2014 -0400

----------------------------------------------------------------------
 .../test/java/org/apache/cxf/systest/ws/cache/CachingTest.java   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/0a0b9dee/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
index d3c73e8..87030c3 100644
--- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/cache/CachingTest.java
@@ -96,7 +96,7 @@ public class CachingTest extends AbstractBusClientServerTestBase {
         
         // Second invocation
         DoubleItPortType port2 = service.getPort(portQName, DoubleItPortType.class);
-        updateAddressPort(port2, test.getPort());
+        updateAddressPort(port2, PORT);
         
         port2.doubleIt(35);
 
@@ -159,7 +159,7 @@ public class CachingTest extends AbstractBusClientServerTestBase {
         
         // Second invocation
         DoubleItPortType port2 = service.getPort(portQName, DoubleItPortType.class);
-        updateAddressPort(port2, test.getPort());
+        updateAddressPort(port2, PORT);
         
         ((BindingProvider)port2).getRequestContext().put(
             SecurityConstants.CACHE_IDENTIFIER, "proxy2"