You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2013/07/18 11:19:41 UTC
svn commit: r1504398 - in /webservices/wss4j/trunk: parent/
ws-security-common/
ws-security-common/src/main/java/org/apache/wss4j/common/cache/
ws-security-common/src/test/java/org/apache/wss4j/common/cache/
ws-security-common/src/test/resources/ ws-se...
Author: coheigea
Date: Thu Jul 18 09:19:41 2013
New Revision: 1504398
URL: http://svn.apache.org/r1504398
Log:
[WSS-466] - assure compatibility with the change in ehcache CacheManager's create method from version 2.5.1 to 2.5.2 and up
Added:
webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/
webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/EHCacheManagerHolderTest.java
webservices/wss4j/trunk/ws-security-common/src/test/resources/test-ehcache.xml
Modified:
webservices/wss4j/trunk/parent/pom.xml
webservices/wss4j/trunk/ws-security-common/pom.xml
webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/cache/EHCacheManagerHolder.java
webservices/wss4j/trunk/ws-security-dom/pom.xml
webservices/wss4j/trunk/ws-security-stax/pom.xml
Modified: webservices/wss4j/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/parent/pom.xml?rev=1504398&r1=1504397&r2=1504398&view=diff
==============================================================================
--- webservices/wss4j/trunk/parent/pom.xml (original)
+++ webservices/wss4j/trunk/parent/pom.xml Thu Jul 18 09:19:41 2013
@@ -37,7 +37,7 @@
<properties>
<bcprov.version>1.49</bcprov.version>
- <ehcache.version>2.5.1</ehcache.version>
+ <ehcache.version>2.7.2</ehcache.version>
<log4j.version>1.2.17</log4j.version>
<neethi.version>3.0.2</neethi.version>
<slf4j.version>1.7.5</slf4j.version>
@@ -144,7 +144,7 @@
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache-core</artifactId>
+ <artifactId>ehcache</artifactId>
<version>${ehcache.version}</version>
</dependency>
</dependencies>
Modified: webservices/wss4j/trunk/ws-security-common/pom.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/pom.xml?rev=1504398&r1=1504397&r2=1504398&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/pom.xml (original)
+++ webservices/wss4j/trunk/ws-security-common/pom.xml Thu Jul 18 09:19:41 2013
@@ -273,7 +273,7 @@
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache-core</artifactId>
+ <artifactId>ehcache</artifactId>
<scope>compile</scope>
<optional>true</optional>
</dependency>
Modified: webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/cache/EHCacheManagerHolder.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/cache/EHCacheManagerHolder.java?rev=1504398&r1=1504397&r2=1504398&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/cache/EHCacheManagerHolder.java (original)
+++ webservices/wss4j/trunk/ws-security-common/src/main/java/org/apache/wss4j/common/cache/EHCacheManagerHolder.java Thu Jul 18 09:19:41 2013
@@ -21,10 +21,12 @@ package org.apache.wss4j.common.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,29 @@ public final class EHCacheManagerHolder
org.slf4j.LoggerFactory.getLogger(EHCacheManagerHolder.class);
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 ehcache 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
+ LOG.warn(t.getMessage());
+ }
+ }
+ }
private EHCacheManagerHolder() {
//utility
@@ -73,9 +98,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());
@@ -119,7 +144,7 @@ public final class EHCacheManagerHolder
+ busId;
conf.getDiskStoreConfiguration().setPath(path);
}
- return CacheManager.create(conf);
+ return createCacheManager(conf);
} catch (Throwable t) {
return null;
}
@@ -136,5 +161,28 @@ public final class EHCacheManagerHolder
cacheManager.shutdown();
}
}
-
+
+ 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: webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/EHCacheManagerHolderTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/EHCacheManagerHolderTest.java?rev=1504398&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/EHCacheManagerHolderTest.java (added)
+++ webservices/wss4j/trunk/ws-security-common/src/test/java/org/apache/wss4j/common/cache/EHCacheManagerHolderTest.java Thu Jul 18 09:19:41 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.wss4j.common.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("/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: webservices/wss4j/trunk/ws-security-common/src/test/resources/test-ehcache.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-common/src/test/resources/test-ehcache.xml?rev=1504398&view=auto
==============================================================================
--- webservices/wss4j/trunk/ws-security-common/src/test/resources/test-ehcache.xml (added)
+++ webservices/wss4j/trunk/ws-security-common/src/test/resources/test-ehcache.xml Thu Jul 18 09:19:41 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>
Modified: webservices/wss4j/trunk/ws-security-dom/pom.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/pom.xml?rev=1504398&r1=1504397&r2=1504398&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/pom.xml (original)
+++ webservices/wss4j/trunk/ws-security-dom/pom.xml Thu Jul 18 09:19:41 2013
@@ -208,7 +208,7 @@
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache-core</artifactId>
+ <artifactId>ehcache</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
Modified: webservices/wss4j/trunk/ws-security-stax/pom.xml
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/pom.xml?rev=1504398&r1=1504397&r2=1504398&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/pom.xml (original)
+++ webservices/wss4j/trunk/ws-security-stax/pom.xml Thu Jul 18 09:19:41 2013
@@ -161,7 +161,7 @@
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
- <artifactId>ehcache-core</artifactId>
+ <artifactId>ehcache</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>