You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2004/11/19 08:29:34 UTC

svn commit: r105787 - struts/core/trunk/src/share/org/apache/struts/action

Author: mrdon
Date: Thu Nov 18 23:29:33 2004
New Revision: 105787

Modified:
   struts/core/trunk/src/share/org/apache/struts/action/ActionServlet.java
Log:
Adding better handling of servlet initialization errors to mark the
servlet as unavailable and notify the developer of the probable cause


Modified: struts/core/trunk/src/share/org/apache/struts/action/ActionServlet.java
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/action/ActionServlet.java	(original)
+++ struts/core/trunk/src/share/org/apache/struts/action/ActionServlet.java	Thu Nov 18 23:29:33 2004
@@ -317,37 +317,54 @@
      */
     public void init() throws ServletException {
 
-        initInternal();
-        initOther();
-        initServlet();
-
-        getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
-        initModuleConfigFactory();
-        // Initialize modules as needed
-        ModuleConfig moduleConfig = initModuleConfig("", config);
-        initModuleMessageResources(moduleConfig);
-        initModuleDataSources(moduleConfig);
-        initModulePlugIns(moduleConfig);
-        moduleConfig.freeze();
-
-        Enumeration names = getServletConfig().getInitParameterNames();
-        while (names.hasMoreElements()) {
-            String name = (String) names.nextElement();
-            if (!name.startsWith("config/")) {
-                continue;
-            }
-            String prefix = name.substring(6);
-            moduleConfig = initModuleConfig
-                (prefix, getServletConfig().getInitParameter(name));
+        // Wraps the entire initialization in a try/catch to better handle
+        // unexpected exceptions and errors to provide better feedback
+        // to the developer
+        try {
+            initInternal();
+            initOther();
+            initServlet();
+    
+            getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this);
+            initModuleConfigFactory();
+            // Initialize modules as needed
+            ModuleConfig moduleConfig = initModuleConfig("", config);
             initModuleMessageResources(moduleConfig);
             initModuleDataSources(moduleConfig);
             initModulePlugIns(moduleConfig);
             moduleConfig.freeze();
-        }
-
-        this.initModulePrefixes(this.getServletContext());
+    
+            Enumeration names = getServletConfig().getInitParameterNames();
+            while (names.hasMoreElements()) {
+                String name = (String) names.nextElement();
+                if (!name.startsWith("config/")) {
+                    continue;
+                }
+                String prefix = name.substring(6);
+                moduleConfig = initModuleConfig
+                    (prefix, getServletConfig().getInitParameter(name));
+                initModuleMessageResources(moduleConfig);
+                initModuleDataSources(moduleConfig);
+                initModulePlugIns(moduleConfig);
+                moduleConfig.freeze();
+            }
+    
+            this.initModulePrefixes(this.getServletContext());
+    
+            this.destroyConfigDigester();
+        } catch (UnavailableException ex) {
+            throw ex;
+        } catch (Throwable t) {
 
-        this.destroyConfigDigester();
+            // The follow error message is not retrieved from internal message
+            // resources as they may not have been able to have been 
+            // initialized
+            log.error("Unable to initialize Struts ActionServlet due to an "
+                + "unexpected exception or error thrown, so marking the "
+                + "servlet as unavailable.  Most likely, this is due to an "
+                + "incorrect or missing library dependency.", t);
+            throw new UnavailableException(t.getMessage());
+        }    
     }
 
     /**

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org