struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r476696 - in /struts/struts2/trunk/core/src: main/java/org/apache/struts2/ main/java/org/apache/struts2/dispatcher/ main/java/org/apache/struts2/portlet/dispatcher/ test/java/org/apache/struts2/dispatcher/ test/java/org/apache/struts2/views...
Date Sun, 19 Nov 2006 03:56:18 GMT
Author: tmjee
Date: Sat Nov 18 19:56:18 2006
New Revision: 476696

URL: http://svn.apache.org/viewvc?view=rev&rev=476696
Log:
WW-1513
 - Dispatcher's setConfigurationManager() method has no effect


Modified:
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsTestCase.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
    struts/struts2/trunk/core/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/DispatcherTest.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
    struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsTestCase.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsTestCase.java?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsTestCase.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/StrutsTestCase.java Sat Nov
18 19:56:18 2006
@@ -53,6 +53,7 @@
             params = new HashMap<String,String>();
         }
         Dispatcher du = new Dispatcher(new MockServletContext(), params);
+        du.init();
         Dispatcher.setInstance(du);
         configurationManager = du.getConfigurationManager();
         configuration = configurationManager.getConfiguration();

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?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- 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
Sat Nov 18 19:56:18 2006
@@ -189,14 +189,19 @@
         dispatcherListeners.remove(listener);
     }
 
+    private ServletContext servletContext;
+    private Map<String, String> initParams;
+    
+    
     /**
      * Create the Dispatcher instance for a given ServletContext and set of initialization
parameters.
      *
      * @param servletContext Our servlet context
      * @param initParams The set of initialization parameters
      */
-    public Dispatcher(ServletContext servletContext, Map initParams) {
-        init(servletContext, initParams);
+    public  Dispatcher(ServletContext servletContext, Map<String, String> initParams)
{
+        this.servletContext = servletContext;
+        this.initParams = initParams;
     }
 
     /**
@@ -275,15 +280,18 @@
     /**
      * Load configurations, including both XML and zero-configuration strategies,
      * and update optional settings, including whether to reload configurations and resource
files. 
-     *
-     * @param servletContext Our servlet context
-     * @param initParams The set of initialization parameters
      */
-    private void init(final ServletContext servletContext, final Map<String,String>
initParams) {
+    public void init() {
         
-        configurationManager = new ConfigurationManager(BeanSelectionProvider.DEFAULT_BEAN_NAME);
+    	if (configurationManager == null) {
+    		configurationManager = new ConfigurationManager(BeanSelectionProvider.DEFAULT_BEAN_NAME);
+    	}
         
+    	// 1] Configuration: legacy properties file (struts.properties)
         configurationManager.addConfigurationProvider(new LegacyPropertiesConfigurationProvider());
+        
+        
+        // 2] Configuration: traditional xml configuration (eg. struts-default.xml, struts-plugin.xml,
struts.xml)
         // Load traditional xml configuration
         String configPaths = initParams.get("config");
         if (configPaths == null) {
@@ -302,6 +310,7 @@
             }
         }
 
+        // 3] Configuration: zero-configuration stuff
         // Load configuration from a scan of the classloader
         String packages = initParams.get("actionPackages");
         if (packages != null) {
@@ -314,6 +323,7 @@
             }
         }
         
+        // 4] Configuration: custom ConfigurationProviders
         String configProvs = initParams.get("configProviders");
         if (configProvs != null) {
             String[] classes = configProvs.split("\\s*[,]\\s*");
@@ -332,6 +342,7 @@
             }
         }
         
+        // 5] Configurations: Filter's init-parameters as constants to be injected
         // Load filter init params as constants
         configurationManager.addConfigurationProvider(new ConfigurationProvider() {
             public void destroy() {}
@@ -344,6 +355,8 @@
             }
         });
         
+        
+        // 6] Configurations: Alias standard Struts2 beans
         configurationManager.addConfigurationProvider(new BeanSelectionProvider());
         // Preload the configuration
         Configuration config = configurationManager.getConfiguration();

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java
Sat Nov 18 19:56:18 2006
@@ -207,8 +207,11 @@
      * @param filterConfig The filter configuration
      */
     public void init(FilterConfig filterConfig) throws ServletException {
+    	 this.filterConfig = filterConfig;
+    	 
         dispatcher = createDispatcher(filterConfig);
-        this.filterConfig = filterConfig;
+        dispatcher.init();
+       
         String param = filterConfig.getInitParameter("packages");
         String packages = "org.apache.struts2.static template org.apache.struts2.interceptor.debugging";
         if (param != null) {
@@ -388,6 +391,7 @@
      */
     public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws
IOException, ServletException {
 
+    	
         HttpServletRequest request = (HttpServletRequest) req;
         HttpServletResponse response = (HttpServletResponse) res;
         ServletContext servletContext = getServletContext();

Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
(original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
Sat Nov 18 19:56:18 2006
@@ -187,6 +187,7 @@
         
         Dispatcher.setPortletSupportActive(true);
         dispatcherUtils = new Dispatcher(ServletContextHolderListener.getServletContext(),
params);
+        dispatcherUtils.init();
         
         // For testability
         if (factory == 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?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- 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
Sat Nov 18 19:56:18 2006
@@ -110,13 +110,13 @@
     
     public void testConfigurationManager() {
     	Dispatcher du = null;
-    	final InternalConfigurationManager configurationManager = new InternalConfigurationManager();
+    	InternalConfigurationManager configurationManager = new InternalConfigurationManager();
     	try {
-    		du = new Dispatcher(new MockServletContext(), new HashMap<String, String>())
{
-    			{
-    				setConfigurationManager(configurationManager);
-    			}
-    		};
+    		du = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
+    		du.setConfigurationManager(configurationManager);
+    		
+    		du.init();
+    		
             Dispatcher.setInstance(du);
             
             assertFalse(configurationManager.destroyConfiguration);

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterDispatcherTest.java
Sat Nov 18 19:56:18 2006
@@ -44,6 +44,8 @@
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.config.ConfigurationManager;
 import com.opensymphony.xwork2.config.impl.DefaultConfiguration;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.inject.ContainerBuilder;
 
 /**
  * FilterDispatcher TestCase.
@@ -128,8 +130,15 @@
         final InnerDispatcher _dispatcher = new InnerDispatcher(servletContext);
         Dispatcher.setInstance(null);
 
+        DefaultConfiguration conf = new DefaultConfiguration() {
+        	@Override
+        	public Container getContainer() {
+        		return new ContainerBuilder().create(false);
+        	}
+        };
+       
         ConfigurationManager confManager = new ConfigurationManager();
-        confManager.setConfiguration(new DefaultConfiguration());
+        confManager.setConfiguration(conf);
         _dispatcher.setConfigurationManager(confManager);
 
 
@@ -142,8 +151,8 @@
                 return _dispatcher;
             }
         };
-        filter.init(filterConfig);
         filter.setActionMapper(new InnerActionMapper());
+        filter.init(filterConfig);
         filter.doFilter(req, res, chain);
 
         assertTrue(_dispatcher.wrappedRequest);

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/dispatcher/FilterTest.java
Sat Nov 18 19:56:18 2006
@@ -33,7 +33,6 @@
 
 import junit.framework.TestCase;
 
-import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.dispatcher.mapper.ActionMapper;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
 import org.springframework.mock.web.MockFilterConfig;
@@ -124,7 +123,7 @@
                 filterDispatcherCreateDispatcherCount++;
                 return _dispatcher2;
             }
-
+            
             @Override
             public String toString() {
                 return "filterDispatcher";
@@ -132,32 +131,35 @@
         };
     }
 
-
     public void testUsingFilterDispatcherOnly() throws Exception {
         ObjectFactory oldObjecFactory = ObjectFactory.getObjectFactory();
         try {
             ObjectFactory.setObjectFactory(new InnerObjectFactory());
-            filterDispatcher.setActionMapper(new FilterTest.InnerMapper());
 
             assertEquals(cleanUpFilterCreateDispatcherCount, 0);
             assertEquals(filterDispatcherCreateDispatcherCount, 0);
+            assertFalse(_dispatcher1.init);
             assertFalse(_dispatcher1.prepare);
             assertFalse(_dispatcher1.wrapRequest);
             assertFalse(_dispatcher1.service);
+            assertFalse(_dispatcher2.init);
             assertFalse(_dispatcher2.prepare);
             assertFalse(_dispatcher2.wrapRequest);
             assertFalse(_dispatcher2.service);
 
             filterDispatcher.init(filterConfig);
+            FilterDispatcher.setActionMapper(new FilterTest.InnerMapper());
             filterDispatcher.doFilter(request, response, filterChain2);
             filterDispatcher.destroy();
 
             // we are using FilterDispatcher only, so cleanUp filter's Dispatcher should
not be created.
             assertEquals(cleanUpFilterCreateDispatcherCount, 0);
             assertEquals(filterDispatcherCreateDispatcherCount, 1);
+            assertFalse(_dispatcher1.init);
             assertFalse(_dispatcher1.prepare);
             assertFalse(_dispatcher1.wrapRequest);
             assertFalse(_dispatcher1.service);
+            assertTrue(_dispatcher2.init);
             assertTrue(_dispatcher2.prepare);
             assertTrue(_dispatcher2.wrapRequest);
             assertTrue(_dispatcher2.service);
@@ -168,6 +170,7 @@
         }
     }
 
+
     public void testUsingFilterDispatcherOnly_Multiple() throws Exception {
         ObjectFactory oldObjecFactory = ObjectFactory.getObjectFactory();
         try {
@@ -179,11 +182,14 @@
             assertFalse(_dispatcher1.prepare);
             assertFalse(_dispatcher1.wrapRequest);
             assertFalse(_dispatcher1.service);
+            assertFalse(_dispatcher1.cleanUp);
             assertFalse(_dispatcher2.prepare);
             assertFalse(_dispatcher2.wrapRequest);
             assertFalse(_dispatcher2.service);
+            assertFalse(_dispatcher2.cleanUp);
 
             filterDispatcher.init(filterConfig);
+            FilterDispatcher.setActionMapper(new FilterTest.InnerMapper());
             filterDispatcher.doFilter(request, response, filterChain2);
             filterDispatcher.doFilter(request, response, filterChain2);
             filterDispatcher.destroy();
@@ -194,9 +200,11 @@
             assertFalse(_dispatcher1.prepare);
             assertFalse(_dispatcher1.wrapRequest);
             assertFalse(_dispatcher1.service);
+            assertFalse(_dispatcher1.cleanUp);
             assertTrue(_dispatcher2.prepare);
             assertTrue(_dispatcher2.wrapRequest);
             assertTrue(_dispatcher2.service);
+            assertTrue(_dispatcher2.cleanUp);
             assertTrue(Dispatcher.getInstance() == null);
         }
         finally {
@@ -204,6 +212,8 @@
         }
     }
 
+    
+
     /*public void testUsingCleanUpAndFilterDispatcher() throws Exception {
         ObjectFactory oldObjecFactory = ObjectFactory.getObjectFactory();
         try {
@@ -281,12 +291,19 @@
 
 
     class InnerDispatcher extends Dispatcher {
+    	public boolean init = false;
         public boolean prepare = false;
         public boolean wrapRequest = false;
         public boolean service = false;
+        public boolean cleanUp = false;
 
         public InnerDispatcher(ServletContext servletContext) {
-            super(servletContext, new HashMap());
+            super(servletContext, new HashMap<String, String>());
+        }
+        
+        @Override
+        public void init() {
+        	init= true;
         }
 
         @Override
@@ -303,6 +320,11 @@
         @Override
         public void serviceAction(HttpServletRequest request, HttpServletResponse response,
ServletContext context, ActionMapping mapping) throws ServletException {
             service = true;
+        }
+        
+        @Override
+        public void cleanup() {
+        	cleanUp = true;
         }
     }
 

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/AbstractTagTest.java
Sat Nov 18 19:56:18 2006
@@ -108,6 +108,7 @@
 
         mockContainer = new Mock(Container.class);
         Dispatcher du = new Dispatcher(pageContext.getServletContext(), new HashMap());
+        du.init();
         Dispatcher.setInstance(du);
         du.setConfigurationManager(configurationManager);
         session = new SessionMap(request);

Modified: struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java?view=diff&rev=476696&r1=476695&r2=476696
==============================================================================
--- struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
(original)
+++ struts/struts2/trunk/core/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
Sat Nov 18 19:56:18 2006
@@ -80,7 +80,9 @@
     public void setUp() throws Exception {
         super.setUp();
 
-        Dispatcher.setInstance(new Dispatcher(null, new HashMap()));
+        Dispatcher du = new Dispatcher(null, new HashMap());
+        du.init();
+        Dispatcher.setInstance(du);
 
         mockPortletApiAvailable();
 



Mime
View raw message