You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ri...@apache.org on 2004/12/13 06:14:06 UTC

svn commit: r111689 - in incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow: . config

Author: rich
Date: Sun Dec 12 21:14:05 2004
New Revision: 111689

URL: http://svn.apache.org/viewcvs?view=rev&rev=111689
Log:
- Beginning of work to upgrade from Struts 1.1 to 1.2.x:
    * Got rid of legacy (Struts 1.0) behavior in AutoRegisterActionServlet, namely, the initialization of deprecated collections (ActionForwards, ActionMappings, ActionFormBeans) in the ServletContext.
    * Workaround for http://issues.apache.org/bugzilla/show_bug.cgi?id=32661.

- Fixed an assertion error while parsing generated Struts config files in webapps that contained no shared flows (*.jpfs) and no (deprecated) Global.app.

DRT: netui (WinXP)
BB: self (linux)


Modified:
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
   incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowControllerConfig.java

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java?view=diff&rev=111689&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java&r1=111688&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java&r2=111689
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/AutoRegisterActionServlet.java	Sun Dec 12 21:14:05 2004
@@ -17,61 +17,49 @@
  */
 package org.apache.beehive.netui.pageflow;
 
+import org.apache.beehive.netui.pageflow.internal.ContextCache;
+import org.apache.beehive.netui.pageflow.internal.InternalConstants;
+import org.apache.beehive.netui.pageflow.internal.InternalUtils;
+import org.apache.beehive.netui.util.Bundle;
+import org.apache.beehive.netui.util.DiscoveryUtils;
+import org.apache.beehive.netui.util.config.ConfigUtil;
+import org.apache.beehive.netui.util.config.bean.ModuleConfigLocators;
+import org.apache.beehive.netui.util.config.bean.PageflowConfig;
+import org.apache.beehive.netui.util.logging.Logger;
+import org.apache.commons.digester.Digester;
+import org.apache.struts.Globals;
 import org.apache.struts.action.ActionServlet;
-import org.apache.struts.action.RequestProcessor;
 import org.apache.struts.action.DynaActionFormClass;
-import org.apache.struts.action.ActionFormBeans;
-import org.apache.struts.action.ActionFormBean;
-import org.apache.struts.action.ActionForwards;
-import org.apache.struts.action.ActionForward;
-import org.apache.struts.action.ActionMappings;
-import org.apache.struts.action.ActionMapping;
-import org.apache.struts.config.ModuleConfig;
-import org.apache.struts.config.ModuleConfigFactory;
-import org.apache.struts.config.FormBeanConfig;
+import org.apache.struts.action.RequestProcessor;
 import org.apache.struts.config.ControllerConfig;
-import org.apache.struts.config.ForwardConfig;
-import org.apache.struts.config.ActionConfig;
+import org.apache.struts.config.FormBeanConfig;
 import org.apache.struts.config.MessageResourcesConfig;
+import org.apache.struts.config.ModuleConfig;
+import org.apache.struts.config.ModuleConfigFactory;
 import org.apache.struts.config.impl.ModuleConfigImpl;
 import org.apache.struts.util.RequestUtils;
-import org.apache.struts.Globals;
-import org.apache.commons.digester.Digester;
 import org.xml.sax.InputSource;
 
-import javax.servlet.ServletException;
-import javax.servlet.UnavailableException;
 import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletResponse;
+import javax.servlet.UnavailableException;
 import javax.servlet.http.HttpServletRequest;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Enumeration;
-import java.util.Collections;
-import java.util.ArrayList;
-import java.util.concurrent.ConcurrentHashMap;
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ObjectOutputStream;
 import java.io.ObjectInputStream;
-import java.net.URL;
+import java.io.ObjectOutputStream;
 import java.net.MalformedURLException;
-
-import org.apache.beehive.netui.util.Bundle;
-import org.apache.beehive.netui.util.ServletUtils;
-import org.apache.beehive.netui.util.DiscoveryUtils;
-import org.apache.beehive.netui.util.config.ConfigUtil;
-import org.apache.beehive.netui.util.config.bean.PageflowConfig;
-import org.apache.beehive.netui.util.config.bean.ModuleConfigLocators;
-import org.apache.beehive.netui.util.logging.Logger;
-import org.apache.beehive.netui.pageflow.internal.ContextCache;
-import org.apache.beehive.netui.pageflow.internal.InternalUtils;
-import org.apache.beehive.netui.pageflow.internal.RequestValues;
-import org.apache.beehive.netui.pageflow.internal.InternalConstants;
-import org.apache.beehive.netui.pageflow.handler.ForwardRedirectHandler;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 
 /**
@@ -82,11 +70,14 @@
  */
 public class AutoRegisterActionServlet extends ActionServlet
 {
+    /**
+     * @deprecated To register {@link ModuleConfigLocator}s, use the <code>module-config-locators</code> element
+     *             in <code>pageflow-config</code> of /WEB-INF/netui-config.xml.
+     */ 
     public static String MODULE_CONFIG_LOCATOR_CLASS_ATTR = "moduleConfigLocators";
     
     /** Map of module-path to ModuleConfig */
     private Map< String, ModuleConfig > _registeredModules = new ConcurrentHashMap< String, ModuleConfig >();
-    private boolean _hasDataSources = false;
     private transient Digester _cachedConfigDigester = null;
     private Map _configParams = null;
     private ModuleConfigLocator[] _moduleConfigLocators = null;
@@ -157,7 +148,7 @@
             }
         }
         
-        _moduleConfigLocators = locators.toArray( new ModuleConfigLocator[0] ); 
+        _moduleConfigLocators = locators.toArray( new ModuleConfigLocator[locators.size()] ); 
     }
     
     private static void addModuleConfigLocator( String locatorClassName, ArrayList< ModuleConfigLocator > locators )
@@ -242,7 +233,7 @@
                 catch ( MalformedURLException e )
                 {
                     _log.error( "ModuleConfigLocator " + locator.getClass().getName()
-                                + " returned an invalid path: " + moduleConfigPath + ".", e );
+                                + " returned an invalid path: " + moduleConfigPath + '.', e );
                 }
             }
         }
@@ -283,14 +274,14 @@
         }
         else
         {
-            ServletConfig config = getServletConfig();
-            assert config != null;
+            ServletConfig servletConfig = getServletConfig();
+            assert servletConfig != null;
             HashMap params = new HashMap();
             
-            for ( Enumeration e = config.getInitParameterNames(); e.hasMoreElements(); )
+            for ( Enumeration e = servletConfig.getInitParameterNames(); e.hasMoreElements(); )
             {
                 String name = ( String ) e.nextElement();
-                params.put( name, config.getInitParameter( name ) );
+                params.put( name, servletConfig.getInitParameter( name ) );
             }
             
             stream.writeObject( params );
@@ -333,38 +324,6 @@
     }
 
     /**
-     * @exclude
-     */ 
-    protected void initModuleDataSources( ModuleConfig config )
-            throws ServletException
-    {
-        //
-        // This is part of a workaround for some strange behavior on webapp redeploy, which
-        // indirectly calls destroyDataSources.  We keep track of whether there are any
-        // datasources configured, and if there are not, we don't call the base destroyDataSources().
-        //
-        super.initModuleDataSources( config );
-        _hasDataSources = ! dataSources.isEmpty();
-    }
-    
-    /**
-     * @exclude
-     */ 
-    protected void destroyDataSources()
-    {
-        //
-        // This is part of a workaround for some strange behavior on webapp redeploy, which
-        // indirectly calls destroyDataSources.  We keep track of whether there are any
-        // datasources configured, and if there are not, we don't call the base destroyDataSources().
-        //
-        if ( _hasDataSources )
-        {
-            super.destroyDataSources();
-        }
-    }
-        
-        
-    /**
      * This method is almost exactly the same as the base class initModuleConfig.  The only difference
      * is that it does not throw an UnavailableException if a module configuration file is missing or
      * invalid.
@@ -377,24 +336,25 @@
 
         if ( _log.isDebugEnabled() )
         {
-            _log.debug( "Initializing module path '" + prefix + "' configuration from '" + paths + "'" );
+            _log.debug( "Initializing module path '" + prefix + "' configuration from '" + paths + '\'' );
         }
 
         // Parse the configuration for this module
-        ModuleConfig config = null;
+        ModuleConfig moduleConfig = null;
         InputStream input = null;
-        String mapping = null;
+        String mapping;
+        
         try
         {
             ModuleConfigFactory factoryObject =
                     ModuleConfigFactory.createFactory();
-            config = factoryObject.createModuleConfig( prefix );
+            moduleConfig = factoryObject.createModuleConfig( prefix );
 
             // Support for module-wide ActionMapping type override
             mapping = getServletConfig().getInitParameter( "mapping" );
             if ( mapping != null )
             {
-                config.setActionMappingClass( mapping );
+                moduleConfig.setActionMappingClass( mapping );
             }
 
             // Configure the Digester instance we will use
@@ -403,8 +363,8 @@
             // Process each specified resource path
             while ( paths.length() > 0 )
             {
-                digester.push( config );
-                String path = null;
+                digester.push( moduleConfig );
+                String path;
                 int comma = paths.indexOf( ',' );
                 if ( comma >= 0 )
                 {
@@ -436,7 +396,7 @@
                     try
                     {
                         digester.parse( is );
-                        getServletContext().setAttribute( Globals.MODULE_KEY + prefix, config );
+                        getServletContext().setAttribute( Globals.MODULE_KEY + prefix, moduleConfig );
                     }
                     catch ( Exception e )
                     {
@@ -463,7 +423,7 @@
                         // Set the ControllerConfig to a MissingRootModuleControllerConfig.  This is used by
                         // PageFlowRequestProcessor.
                         //
-                        config.setControllerConfig( new MissingRootModuleControllerConfig() );
+                        moduleConfig.setControllerConfig( new MissingRootModuleControllerConfig() );
                     }
                     else
                     {
@@ -495,7 +455,7 @@
 
         // Force creation and registration of DynaActionFormClass instances
         // for all dynamic form beans we wil be using
-        FormBeanConfig fbs[] = config.findFormBeanConfigs();
+        FormBeanConfig fbs[] = moduleConfig.findFormBeanConfigs();
         for ( int i = 0; i < fbs.length; i++ )
         {
             if ( fbs[i].getDynamic() )
@@ -508,16 +468,13 @@
         // backwards compatibility only, will be removed later)
         if ( prefix.length() < 1 )
         {
-            defaultControllerConfig( config );
-            defaultMessageResourcesConfig( config );
-            defaultFormBeansConfig( config );
-            defaultForwardsConfig( config );
-            defaultMappingsConfig( config );
+            defaultControllerConfig( moduleConfig );
+            defaultMessageResourcesConfig( moduleConfig );
         }
 
         // Return the completed configuration object
         //config.freeze();  // Now done after plugins init
-        return ( config );
+        return moduleConfig;
 
     }
 
@@ -886,83 +843,6 @@
         }
 
     }
-
-
-    /**
-     * Perform backwards-compatible configuration of an ActionFormBeans
-     * collection, and expose it as a servlet context attribute (as was
-     * used in Struts 1.0).  Note that the current controller code does
-     * not (and should not) reference this attribute for any reason.
-     *
-     * @param config The ModuleConfig object for the default app
-     *
-     * @since Struts 1.1
-     * @deprecated Will be removed in a release after Struts 1.1.
-     */
-    private void defaultFormBeansConfig(ModuleConfig config) {
-
-        FormBeanConfig fbcs[] = config.findFormBeanConfigs();
-        ActionFormBeans afb = new ActionFormBeans();
-        afb.setFast(false);
-        for (int i = 0; i < fbcs.length; i++) {
-            afb.addFormBean((ActionFormBean) fbcs[i]);
-        }
-        afb.setFast(true);
-        getServletContext().setAttribute(Globals.FORM_BEANS_KEY, afb);
-
-    }
-
-
-    /**
-     * Perform backwards-compatible configuration of an ActionForwards
-     * collection, and expose it as a servlet context attribute (as was
-     * used in Struts 1.0).  Note that the current controller code does
-     * not (and should not) reference this attribute for any reason.
-     *
-     * @param config The ModuleConfig object for the default app
-     *
-     * @since Struts 1.1
-     * @deprecated Will be removed in a release after Struts 1.1.
-     */
-    private void defaultForwardsConfig(ModuleConfig config) {
-
-        ForwardConfig fcs[] = config.findForwardConfigs();
-        ActionForwards af = new ActionForwards();
-        af.setFast(false);
-        for (int i = 0; i < fcs.length; i++) {
-            af.addForward((ActionForward) fcs[i]);
-        }
-        af.setFast(true);
-        getServletContext().setAttribute(Globals.FORWARDS_KEY, af);
-
-    }
-
-
-    /**
-     * Perform backwards-compatible configuration of an ActionMappings
-     * collection, and expose it as a servlet context attribute (as was
-     * used in Struts 1.0).  Note that the current controller code does
-     * not (and should not) reference this attribute for any reason.
-     *
-     * @param config The ModuleConfig object for the default app
-     *
-     * @since Struts 1.1
-     * @deprecated Will be removed in a release after Struts 1.1.
-     */
-    private void defaultMappingsConfig(ModuleConfig config) {
-
-        ActionConfig acs[] = config.findActionConfigs();
-        ActionMappings am = new ActionMappings();
-        am.setServlet(this);
-        am.setFast(false);
-        for (int i = 0; i < acs.length; i++) {
-            am.addMapping((ActionMapping) acs[i]);
-        }
-        am.setFast(true);
-        getServletContext().setAttribute(Globals.MAPPINGS_KEY, am);
-
-    }
-
 
     /**
      * Perform backwards-compatible configuration of the default module's

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java?view=diff&rev=111689&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java&r1=111688&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java&r2=111689
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/PageFlowPageFilter.java	Sun Dec 12 21:14:05 2004
@@ -292,8 +292,15 @@
             das.ensureModuleRegistered( curModulePath, request );
         }
                 
-        RequestUtils.selectModule( curModulePath, request, _servletContext );
-                
+        //
+        // TODO: the only reason we have to do the getModuleConfig check below is that there's an NPE bug in
+        // ModuleUtils.selectModule().  I've entered http://issues.apache.org/bugzilla/show_bug.cgi?id=32661 .
+        //
+        if ( InternalUtils.getModuleConfig( curModulePath, _servletContext ) != null )
+        {
+            RequestUtils.selectModule( curModulePath, request, _servletContext );
+        }
+                    
         if ( RequestUtils.getRequestModuleConfig( request ) == null )
         {
             //

Modified: incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowControllerConfig.java
Url: http://svn.apache.org/viewcvs/incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowControllerConfig.java?view=diff&rev=111689&p1=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowControllerConfig.java&r1=111688&p2=incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowControllerConfig.java&r2=111689
==============================================================================
--- incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowControllerConfig.java	(original)
+++ incubator/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/config/PageFlowControllerConfig.java	Sun Dec 12 21:14:05 2004
@@ -95,6 +95,12 @@
 
     public void setSharedFlows( String sharedFlows )
     {
+        if ( sharedFlows == null || sharedFlows.length() == 0 )
+        {
+            _sharedFlowTypes = null;
+            return;
+        }
+        
         String[] keyValues = sharedFlows.split( "," );
         _sharedFlowTypes = new LinkedHashMap< String, String >();