Author: kkolinko
Date: Sat Jan  5 00:07:05 2013
New Revision: 1429172

URL: http://svn.apache.org/viewvc?rev=1429172&view=rev
Log:
Merged revisions r1428993 r1429167 from tomcat/trunk:
Followup to r1428645
1. in ApplicationFilterConfig.release():
Align implementation between IS_SECURITY_ENABLED==true and ==false branches.
(The difference is i18n and Error handling).
2. in ApplicationFilterConfig constructor and 
ApplicationFilterConfig.setFilterDef() method:
Remove the setFilterDef() method and inline the code into the constructor.
(This avoids the need to fix the filter destruction code in setFilterDef() 
which is actually never called).
The removed method has package visibility, so there should not be any 3rd-party 
callers.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1428993,1429167

Modified: 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java?rev=1429172&r1=1429171&r2=1429172&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 
Sat Jan  5 00:07:05 2013
@@ -101,8 +101,11 @@ public final class ApplicationFilterConf
         super();
 
         this.context = context;
-        setFilterDef(filterDef);
-        if (filterDef.getFilter() != null) {
+        this.filterDef = filterDef;
+        // Allocate a new filter instance if necessary
+        if (filterDef.getFilter() == null) {
+            getFilter();
+        } else {
             this.filter = filterDef.getFilter();
             getInstanceManager().newInstance(filter);
             initFilter();
@@ -128,7 +131,7 @@ public final class ApplicationFilterConf
     /**
      * The <code>FilterDef</code> that defines our associated Filter.
      */
-    private FilterDef filterDef = null;
+    private final FilterDef filterDef;
 
     /**
      * the InstanceManager used to create and destroy filter instances.
@@ -301,23 +304,22 @@ public final class ApplicationFilterConf
         
         if (this.filter != null)
         {
-            if (Globals.IS_SECURITY_ENABLED) {
-                try {
-                    SecurityUtil.doAsPrivilege("destroy", filter);
-                } catch(java.lang.Exception ex){
-                    
context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex);
-                }
-                SecurityUtil.remove(filter);
-            } else {
-                try {
+            try {
+                if (Globals.IS_SECURITY_ENABLED) {
+                    try {
+                        SecurityUtil.doAsPrivilege("destroy", filter);
+                    } finally {
+                        SecurityUtil.remove(filter);
+                    }
+                } else {
                     filter.destroy();
-                } catch (Throwable t) {
-                    ExceptionUtils.handleThrowable(t);
-                    context.getLogger().error(sm.getString(
-                            "applicationFilterConfig.release",
-                            filterDef.getFilterName(),
-                            filterDef.getFilterClass()), t);
                 }
+            } catch (Throwable t) {
+                ExceptionUtils.handleThrowable(t);
+                context.getLogger().error(sm.getString(
+                        "applicationFilterConfig.release",
+                        filterDef.getFilterName(),
+                        filterDef.getFilterClass()), t);
             }
             if (!context.getIgnoreAnnotations()) {
                 try {
@@ -335,66 +337,6 @@ public final class ApplicationFilterConf
      }
 
 
-    /**
-     * Set the filter definition we are configured for.  This has the side
-     * effect of instantiating an instance of the corresponding filter class.
-     *
-     * @param filterDef The new filter definition
-     *
-     * @exception ClassCastException if the specified class does not implement
-     *  the <code>javax.servlet.Filter</code> interface
-     * @exception ClassNotFoundException if the filter class cannot be found
-     * @exception IllegalAccessException if the filter class cannot be
-     *  publicly instantiated
-     * @exception InstantiationException if an exception occurs while
-     *  instantiating the filter object
-     * @exception ServletException if thrown by the filter's init() method
-     * @throws NamingException
-     * @throws InvocationTargetException
-     */
-    void setFilterDef(FilterDef filterDef)
-        throws ClassCastException, ClassNotFoundException,
-               IllegalAccessException, InstantiationException,
-               ServletException, InvocationTargetException, NamingException {
-
-        this.filterDef = filterDef;
-        if (filterDef == null) {
-
-            // Release any previously allocated filter instance
-            if (this.filter != null){
-                if (Globals.IS_SECURITY_ENABLED) {
-                    try{
-                        SecurityUtil.doAsPrivilege("destroy", filter);
-                    } catch(java.lang.Exception ex){
-                        
context.getLogger().error("ApplicationFilterConfig.doAsPrivilege", ex);
-                    }
-                    SecurityUtil.remove(filter);
-                } else {
-                    filter.destroy();
-                }
-                if (!context.getIgnoreAnnotations()) {
-                    try {
-                        ((StandardContext) 
context).getInstanceManager().destroyInstance(this.filter);
-                    } catch (Exception e) {
-                        Throwable t = ExceptionUtils
-                                .unwrapInvocationTargetException(e);
-                        ExceptionUtils.handleThrowable(t);
-                        
context.getLogger().error("ApplicationFilterConfig.preDestroy", t);
-                    }
-                }
-            }
-            this.filter = null;
-
-        } else {
-            // Allocate a new filter instance if necessary
-            if (filterDef.getFilter() == null) {
-                getFilter();
-            }
-        }
-
-    }
-
-
     // -------------------------------------------------------- Private Methods
 
     private InstanceManager getInstanceManager() {

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1429172&r1=1429171&r2=1429172&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Sat Jan  5 00:07:05 2013
@@ -72,7 +72,7 @@
       </fix>
       <fix>
         Allow web applications to be stopped cleanly even if filters shown
-        exceptions when their destroy() method is called. (markt)
+        exceptions when their destroy() method is called. (markt/kkolinko)
       </fix>
       <add>
         Make HTTP Digest authentication header parsing tolerant of invalid



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to