WW-4416 Adds support to clear cache under Tomcat 8

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

Branch: refs/heads/master
Commit: a35c3ef4f6211268e04f4c167f14650c88505628
Parents: 60db1aa
Author: Lukasz Lenart <lukaszlen...@apache.org>
Authored: Tue Dec 23 17:04:26 2014 +0100
Committer: Lukasz Lenart <lukaszlen...@apache.org>
Committed: Tue Dec 23 17:04:26 2014 +0100

----------------------------------------------------------------------
 .../xwork2/util/LocalizedTextUtil.java           | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/a35c3ef4/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
----------------------------------------------------------------------
diff --git 
a/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java 
b/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
index b7e147f..1e51ded 100644
--- 
a/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
+++ 
b/xwork-core/src/main/java/com/opensymphony/xwork2/util/LocalizedTextUtil.java
@@ -88,6 +88,8 @@ public class LocalizedTextUtil {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(LocalizedTextUtil.class);
 
+    private static final String TOMCAT_RESOURCE_ENTRIES_FIELD = 
"resourceEntries";
+
     private static final ConcurrentMap<Integer, List<String>> classLoaderMap = 
new ConcurrentHashMap<Integer, List<String>>();
 
     private static boolean reloadBundles = false;
@@ -839,15 +841,28 @@ public class LocalizedTextUtil {
 
         try {
             if 
("org.apache.catalina.loader.WebappClassLoader".equals(cl.getName())) {
-                clearMap(cl, loader, "resourceEntries");
+                clearMap(cl, loader, TOMCAT_RESOURCE_ENTRIES_FIELD);
             } else {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("class loader " + cl.getName() + " is not tomcat 
loader.");
                 }
             }
+        } catch (NoSuchFieldException nsfe) {
+            if 
("org.apache.catalina.loader.WebappClassLoaderBase".equals(cl.getSuperclass().getName()))
 {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Base class #0 doesn't contain '#1' field, 
trying with parent!", nsfe, cl.getName(), TOMCAT_RESOURCE_ENTRIES_FIELD);
+                }
+                try {
+                    clearMap(cl.getSuperclass(), loader, 
TOMCAT_RESOURCE_ENTRIES_FIELD);
+                } catch (Exception e) {
+                    if (LOG.isWarnEnabled()) {
+                        LOG.warn("Couldn't clear tomcat cache using #0", e, 
cl.getSuperclass().getName());
+                    }
+                }
+            }
         } catch (Exception e) {
             if (LOG.isWarnEnabled()) {
-               LOG.warn("couldn't clear tomcat cache", e);
+                   LOG.warn("Couldn't clear tomcat cache", e, cl.getName());
             }
         }
     }

Reply via email to