struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From musa...@apache.org
Subject svn commit: r686328 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/dispatcher/Dispatcher.java test/java/org/apache/struts2/dispatcher/DispatcherTest.java
Date Fri, 15 Aug 2008 19:19:08 GMT
Author: musachy
Date: Fri Aug 15 12:19:07 2008
New Revision: 686328

URL: http://svn.apache.org/viewvc?rev=686328&view=rev
Log:
WW-2381 Destroy method of Interceptor is never called by Struts

Patch provided by D├ęcio Heinzelmann Luckow

Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?rev=686328&r1=686327&r2=686328&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
Fri Aug 15 12:19:07 2008
@@ -24,10 +24,13 @@
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Set;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
@@ -58,10 +61,14 @@
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.config.ConfigurationManager;
 import com.opensymphony.xwork2.config.ConfigurationProvider;
+import com.opensymphony.xwork2.config.entities.InterceptorMapping;
+import com.opensymphony.xwork2.config.entities.InterceptorStackConfig;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
 import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
 import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.ContainerBuilder;
 import com.opensymphony.xwork2.inject.Inject;
+import com.opensymphony.xwork2.interceptor.Interceptor;
 import com.opensymphony.xwork2.util.FileManager;
 import com.opensymphony.xwork2.util.LocalizedTextUtil;
 import com.opensymphony.xwork2.util.ValueStack;
@@ -265,6 +272,22 @@
             }
         }
 
+        // clean up all interceptors by calling their destroy() method
+        Set<Interceptor> interceptors = new HashSet<Interceptor>();
+        Collection<PackageConfig> packageConfigs = configurationManager.getConfiguration().getPackageConfigs().values();
+        for (PackageConfig packageConfig : packageConfigs) {
+            for (Object config : packageConfig.getAllInterceptorConfigs().values()) {
+                if (config instanceof InterceptorStackConfig) {
+                    for (InterceptorMapping interceptorMapping : ((InterceptorStackConfig)
config).getInterceptors()) {
+                	    interceptors.add(interceptorMapping.getInterceptor());
+                    }
+                }
+            }
+        }
+        for (Interceptor interceptor : interceptors) {
+        	interceptor.destroy();
+        }
+
         // clean up configuration
     	configurationManager.destroyConfiguration();
     	configurationManager = null;

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java?rev=686328&r1=686327&r2=686328&view=diff
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
Fri Aug 15 12:19:07 2008
@@ -23,6 +23,7 @@
 
 import java.util.HashMap;
 import java.util.Locale;
+import java.util.Map;
 
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletContext;
@@ -45,10 +46,14 @@
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.ConfigurationManager;
+import com.opensymphony.xwork2.config.entities.InterceptorMapping;
+import com.opensymphony.xwork2.config.entities.InterceptorStackConfig;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
 import com.opensymphony.xwork2.inject.Container;
 import com.opensymphony.xwork2.inject.ContainerBuilder;
 import com.opensymphony.xwork2.inject.Context;
 import com.opensymphony.xwork2.inject.Factory;
+import com.opensymphony.xwork2.interceptor.Interceptor;
 import com.opensymphony.xwork2.util.LocalizedTextUtil;
 
 /**
@@ -159,6 +164,7 @@
         mockConfiguration.expectAndReturn("getContainer", mockContainer.proxy());
         mockContainer.expectAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), destroyedObjectFactory);
         mockConfiguration.expect("destroy");
+        mockConfiguration.matchAndReturn("getPackageConfigs", new HashMap<String, PackageConfig>());
         
         du.setConfigurationManager(cm);
         assertFalse(destroyedObjectFactory.destroyed);
@@ -168,6 +174,40 @@
         mockContainer.verify();
     }
     
+    public void testInterceptorDestroy() throws Exception {           
+        Mock mockInterceptor = new Mock(Interceptor.class);
+        mockInterceptor.matchAndReturn("hashCode", 0);
+        mockInterceptor.expect("destroy");
+        
+        InterceptorMapping interceptorMapping = new InterceptorMapping("test", (Interceptor)
mockInterceptor.proxy());
+        
+        InterceptorStackConfig isc = new InterceptorStackConfig.Builder("test").addInterceptor(interceptorMapping).build();
+        
+        PackageConfig packageConfig = new PackageConfig.Builder("test").addInterceptorStackConfig(isc).build();
+        
+        Map<String, PackageConfig> packageConfigs = new HashMap<String, PackageConfig>();
+        packageConfigs.put("test", packageConfig);
+        
+        Mock mockContainer = new Mock(Container.class);
+        mockContainer.matchAndReturn("getInstance", C.args(C.eq(ObjectFactory.class)), new
ObjectFactory());
+        
+        Mock mockConfiguration = new Mock(Configuration.class);
+        mockConfiguration.matchAndReturn("getPackageConfigs", packageConfigs);
+        mockConfiguration.matchAndReturn("getContainer", mockContainer.proxy());
+        mockConfiguration.expect("destroy");
+        
+        ConfigurationManager configurationManager = new ConfigurationManager();
+        configurationManager.setConfiguration((Configuration) mockConfiguration.proxy());
+        
+        Dispatcher dispatcher = new Dispatcher(new MockServletContext(), new HashMap<String,
String>());
+        dispatcher.setConfigurationManager(configurationManager);
+        dispatcher.cleanup();
+        
+        mockInterceptor.verify();
+        mockContainer.verify();
+        mockConfiguration.verify();
+    }
+    
     class InternalConfigurationManager extends ConfigurationManager {
     	public boolean destroyConfiguration = false;
     	



Mime
View raw message