Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 39C109F21 for ; Wed, 9 May 2012 16:14:05 +0000 (UTC) Received: (qmail 91106 invoked by uid 500); 9 May 2012 16:14:05 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 91054 invoked by uid 500); 9 May 2012 16:14:05 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 91046 invoked by uid 99); 9 May 2012 16:14:05 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 May 2012 16:14:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 09 May 2012 16:14:01 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 352302388847; Wed, 9 May 2012 16:13:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1336269 - in /cxf/branches/2.4.x-fixes: ./ rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/ rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/ Date: Wed, 09 May 2012 16:13:39 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120509161340.352302388847@eris.apache.org> Author: dkulp Date: Wed May 9 16:13:39 2012 New Revision: 1336269 URL: http://svn.apache.org/viewvc?rev=1336269&view=rev Log: Merged revisions 1336257 via svn merge from https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes ........ r1336257 | dkulp | 2012-05-09 12:07:06 -0400 (Wed, 09 May 2012) | 10 lines Merged revisions 1332833 via git cherry-pick from https://svn.apache.org/repos/asf/cxf/trunk ........ r1332833 | dkulp | 2012-05-01 17:15:00 -0400 (Tue, 01 May 2012) | 3 lines [CXF-4279] Try to make sure the ehcache cache manager gets shutdown when we're done with it. ........ ........ Added: cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java - copied unchanged from r1336257, cxf/branches/2.5.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java Modified: cxf/branches/2.4.x-fixes/ (props changed) cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java Propchange: cxf/branches/2.4.x-fixes/ ('svn:mergeinfo' removed) Propchange: cxf/branches/2.4.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java?rev=1336269&r1=1336268&r2=1336269&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java (original) +++ cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheReplayCache.java Wed May 9 16:13:39 2012 @@ -19,6 +19,8 @@ package org.apache.cxf.ws.security.cache; +import java.io.Closeable; +import java.io.IOException; import java.net.URL; import net.sf.ehcache.Cache; @@ -31,7 +33,7 @@ import org.apache.ws.security.cache.Repl * An in-memory EHCache implementation of the ReplayCache interface. The default TTL is 60 minutes and the * max TTL is 12 hours. */ -public class EHCacheReplayCache implements ReplayCache { +public class EHCacheReplayCache implements ReplayCache, Closeable { public static final long DEFAULT_TTL = 3600L; public static final long MAX_TTL = DEFAULT_TTL * 12L; @@ -40,13 +42,7 @@ public class EHCacheReplayCache implemen private long ttl = DEFAULT_TTL; public EHCacheReplayCache(String key, URL configFileURL) { - if (cacheManager == null) { - if (configFileURL == null) { - cacheManager = CacheManager.create(); - } else { - cacheManager = CacheManager.create(configFileURL); - } - } + cacheManager = EHCacheManagerHolder.getCacheManager(configFileURL); if (!cacheManager.cacheExists(key)) { cache = new Cache(key, 50000, true, false, DEFAULT_TTL, DEFAULT_TTL); cacheManager.addCache(cache); @@ -117,5 +113,13 @@ public class EHCacheReplayCache implemen } return false; } + + public void close() throws IOException { + if (cacheManager != null) { + EHCacheManagerHolder.releaseCacheManger(cacheManager); + cacheManager = null; + cache = null; + } + } } Modified: cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java?rev=1336269&r1=1336268&r2=1336269&view=diff ============================================================================== --- cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java (original) +++ cxf/branches/2.4.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/policy/WSSecurityPolicyLoader.java Wed May 9 16:13:39 2012 @@ -19,6 +19,8 @@ package org.apache.cxf.ws.security.policy; +import java.io.Closeable; +import java.io.IOException; import java.util.Arrays; import java.util.List; @@ -26,12 +28,20 @@ import javax.xml.namespace.QName; import org.apache.cxf.Bus; import org.apache.cxf.common.injection.NoJSR250Annotations; +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.endpoint.ClientLifeCycleListener; +import org.apache.cxf.endpoint.ClientLifeCycleManager; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.endpoint.ServerLifeCycleListener; +import org.apache.cxf.endpoint.ServerLifeCycleManager; +import org.apache.cxf.service.model.EndpointInfo; import org.apache.cxf.ws.policy.AssertionBuilderLoader; import org.apache.cxf.ws.policy.AssertionBuilderRegistry; import org.apache.cxf.ws.policy.PolicyBuilder; import org.apache.cxf.ws.policy.PolicyInterceptorProviderLoader; import org.apache.cxf.ws.policy.PolicyInterceptorProviderRegistry; import org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertionBuilder; +import org.apache.cxf.ws.security.SecurityConstants; import org.apache.cxf.ws.security.policy.builders.AlgorithmSuiteBuilder; import org.apache.cxf.ws.security.policy.builders.AsymmetricBindingBuilder; import org.apache.cxf.ws.security.policy.builders.ContentEncryptedElementsBuilder; @@ -76,6 +86,7 @@ import org.apache.cxf.ws.security.policy import org.apache.cxf.ws.security.policy.interceptors.UsernameTokenInterceptorProvider; import org.apache.cxf.ws.security.policy.interceptors.WSSecurityInterceptorProvider; import org.apache.cxf.ws.security.policy.interceptors.WSSecurityPolicyInterceptorProvider; +import org.apache.ws.security.cache.ReplayCache; @NoJSR250Annotations public final class WSSecurityPolicyLoader implements PolicyInterceptorProviderLoader, AssertionBuilderLoader { @@ -92,6 +103,45 @@ public final class WSSecurityPolicyLoade //and error out at that point. If nothing uses ws-securitypolicy //no warnings/errors will display } + ServerLifeCycleManager m = b.getExtension(ServerLifeCycleManager.class); + if (m != null) { + m.registerListener(new ServerLifeCycleListener() { + public void startServer(Server server) { + } + public void stopServer(Server server) { + shutdownResources(server.getEndpoint().getEndpointInfo()); + } + }); + } + ClientLifeCycleManager cm = b.getExtension(ClientLifeCycleManager.class); + if (cm != null) { + cm.registerListener(new ClientLifeCycleListener() { + public void clientCreated(Client client) { + } + @Override + public void clientDestroyed(Client client) { + shutdownResources(client.getEndpoint().getEndpointInfo()); + } + }); + } + } + protected void shutdownResources(EndpointInfo info) { + ReplayCache rc = (ReplayCache)info.getProperty(SecurityConstants.NONCE_CACHE_INSTANCE); + if (rc instanceof Closeable) { + close((Closeable)rc); + } + rc = (ReplayCache)info.getProperty(SecurityConstants.TIMESTAMP_CACHE_INSTANCE); + if (rc instanceof Closeable) { + close((Closeable)rc); + } + } + + private void close(Closeable ts) { + try { + ts.close(); + } catch (IOException ex) { + //ignore, we're shutting down and nothing we can do + } } public void registerBuilders() { AssertionBuilderRegistry reg = bus.getExtension(AssertionBuilderRegistry.class);