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/07/16 15:03:57 UTC
svn commit: r1503703 - in /cxf/branches/2.7.x-fixes/rt/ws/security/src:
main/java/org/apache/cxf/ws/security/cache/
test/java/org/apache/cxf/ws/security/cache/ test/resources/
Author: ay
Date: Tue Jul 16 13:03:56 2013
New Revision: 1503703
URL: http://svn.apache.org/r1503703
Log:
part of CXF-4577 for 2.7.x et al
Added:
cxf/branches/2.7.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/
cxf/branches/2.7.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolderTest.java
cxf/branches/2.7.x-fixes/rt/ws/security/src/test/resources/cxf-test-ehcache.xml (with props)
Modified:
cxf/branches/2.7.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
Modified: cxf/branches/2.7.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java?rev=1503703&r1=1503702&r2=1503703&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java (original)
+++ cxf/branches/2.7.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolder.java Tue Jul 16 13:03:56 2013
@@ -21,10 +21,12 @@ package org.apache.cxf.ws.security.cache
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
+import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
@@ -40,6 +42,28 @@ import org.apache.cxf.resource.ResourceM
public final class EHCacheManagerHolder {
private static final ConcurrentHashMap<String, AtomicInteger> COUNTS
= new ConcurrentHashMap<String, AtomicInteger>(8, 0.75f, 2);
+
+ private static Method cacheManagerCreateMethodNoArg;
+ private static Method createMethodURLArg;
+ private static Method cacheManagerCreateMethodConfigurationArg;
+ static {
+ // these methods are either completely available or absent (valid assumption from 2.5.0 to 2.7.2 so far)
+ try {
+ // from 2.5.2
+ cacheManagerCreateMethodNoArg = CacheManager.class.getMethod("newInstance", (Class<?>[])null);
+ createMethodURLArg = CacheManager.class.getMethod("newInstance", URL.class);
+ cacheManagerCreateMethodConfigurationArg = CacheManager.class.getMethod("newInstance", Configuration.class);
+ } catch (NoSuchMethodException e) {
+ try {
+ // before 2.5.2
+ cacheManagerCreateMethodNoArg = CacheManager.class.getMethod("create", (Class<?>[])null);
+ createMethodURLArg = CacheManager.class.getMethod("create", URL.class);
+ cacheManagerCreateMethodConfigurationArg = CacheManager.class.getMethod("create", Configuration.class);
+ } catch (Throwable t) {
+ // ignore
+ }
+ }
+ }
private EHCacheManagerHolder() {
//utility
@@ -73,9 +97,9 @@ public final class EHCacheManagerHolder
}
if (cacheManager == null) {
if (configFileURL == null) {
- cacheManager = CacheManager.create();
+ cacheManager = createCacheManager();
} else {
- cacheManager = CacheManager.create(configFileURL);
+ cacheManager = createCacheManager(configFileURL);
}
}
AtomicInteger a = COUNTS.get(cacheManager.getName());
@@ -125,7 +149,7 @@ public final class EHCacheManagerHolder
+ busId;
conf.getDiskStoreConfiguration().setPath(path);
}
- return CacheManager.create(conf);
+ return createCacheManager(conf);
} catch (Throwable t) {
return null;
}
@@ -143,4 +167,27 @@ public final class EHCacheManagerHolder
}
}
+ static CacheManager createCacheManager() throws CacheException {
+ try {
+ return (CacheManager)cacheManagerCreateMethodNoArg.invoke(null, (Object[])null);
+ } catch (Exception e) {
+ throw new CacheException(e);
+ }
+ }
+
+ static CacheManager createCacheManager(URL url) throws CacheException {
+ try {
+ return (CacheManager)createMethodURLArg.invoke(null, new Object[]{url});
+ } catch (Exception e) {
+ throw new CacheException(e);
+ }
+ }
+
+ static CacheManager createCacheManager(Configuration conf) throws CacheException {
+ try {
+ return (CacheManager)cacheManagerCreateMethodConfigurationArg.invoke(null, new Object[]{conf});
+ } catch (Exception e) {
+ throw new CacheException(e);
+ }
+ }
}
Added: cxf/branches/2.7.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolderTest.java?rev=1503703&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolderTest.java (added)
+++ cxf/branches/2.7.x-fixes/rt/ws/security/src/test/java/org/apache/cxf/ws/security/cache/EHCacheManagerHolderTest.java Tue Jul 16 13:03:56 2013
@@ -0,0 +1,58 @@
+/**
+ * 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.security.cache;
+
+import net.sf.ehcache.CacheManager;
+import net.sf.ehcache.Status;
+
+import net.sf.ehcache.config.Configuration;
+import net.sf.ehcache.config.ConfigurationFactory;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class EHCacheManagerHolderTest extends Assert {
+
+ @Test
+ public void testCreateCacheManager() {
+ Configuration conf =
+ ConfigurationFactory.parseConfiguration(EHCacheManagerHolder.class.getResource("/cxf-test-ehcache.xml"));
+
+ assertNotNull(conf);
+ conf.setName("testCache");
+
+ CacheManager manager1 = EHCacheManagerHolder.createCacheManager(conf);
+ assertNotNull(manager1);
+ CacheManager manager2 = EHCacheManagerHolder.createCacheManager();
+ assertNotNull(manager2);
+
+ manager1.shutdown();
+ assertEquals(Status.STATUS_SHUTDOWN, manager1.getStatus());
+
+ assertEquals(Status.STATUS_ALIVE, manager2.getStatus());
+
+ manager2.shutdown();
+ assertEquals(Status.STATUS_SHUTDOWN, manager2.getStatus());
+
+ }
+}
Added: cxf/branches/2.7.x-fixes/rt/ws/security/src/test/resources/cxf-test-ehcache.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/ws/security/src/test/resources/cxf-test-ehcache.xml?rev=1503703&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/ws/security/src/test/resources/cxf-test-ehcache.xml (added)
+++ cxf/branches/2.7.x-fixes/rt/ws/security/src/test/resources/cxf-test-ehcache.xml Tue Jul 16 13:03:56 2013
@@ -0,0 +1,16 @@
+<ehcache xsi:noNamespaceSchemaLocation="ehcache.xsd" updateCheck="false" monitoring="autodetect" dynamicConfig="true">
+
+ <diskStore path="java.io.tmpdir"/>
+
+ <defaultCache
+ maxEntriesLocalHeap="5000"
+ eternal="false"
+ timeToIdleSeconds="3600"
+ timeToLiveSeconds="3600"
+ overflowToDisk="true"
+ maxElementsOnDisk="10000000"
+ diskPersistent="false"
+ diskExpiryThreadIntervalSeconds="120"
+ memoryStoreEvictionPolicy="LRU"
+ />
+</ehcache>
Propchange: cxf/branches/2.7.x-fixes/rt/ws/security/src/test/resources/cxf-test-ehcache.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml