craigmcc    01/03/30 14:27:51

  Modified:    catalina/src/share/org/apache/catalina/core
                        StandardContext.java
  Log:
  Any significant error that is encountered while starting a Context initially,
  or as part of a reload() call, will now cause the corresponding web
  application to remain unavailable, rather than allowing it to operate in a
  partially initialized state.
  
  The definition of "significant error" includes failure in initializaing any
  Listener or Filter that is defined in the web.xml file.  Whether or not such
  errors should cause the application startup to fail or not is currently under
  discussion in the JSR-053 expert group.
  
  PR: Bugzilla #1129 (status changed to RESOLVED/REMIND)
  Submitted by: Kevin Jones <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.47      +60 -21    
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java
  
  Index: StandardContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- StandardContext.java      2001/03/24 21:12:25     1.46
  +++ StandardContext.java      2001/03/30 22:27:50     1.47
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
 1.46 2001/03/24 21:12:25 craigmcc Exp $
  - * $Revision: 1.46 $
  - * $Date: 2001/03/24 21:12:25 $
  + * $Header: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
 1.47 2001/03/30 22:27:50 craigmcc Exp $
  + * $Revision: 1.47 $
  + * $Date: 2001/03/30 22:27:50 $
    *
    * ====================================================================
    *
  @@ -140,7 +140,7 @@
    *
    * @author Craig R. McClanahan
    * @author Remy Maucherat
  - * @version $Revision: 1.46 $ $Date: 2001/03/24 21:12:25 $
  + * @version $Revision: 1.47 $ $Date: 2001/03/30 22:27:50 $
    */
   
   public class StandardContext
  @@ -2267,30 +2267,42 @@
   
           // Create and register the associated naming context, if internal 
           // naming is used
  +        boolean ok = false;
           if (isUseNaming()) {
               try {
                   createNamingContext();
               } catch (NamingException e) {
                   log(sm.getString("standardContext.namingInitFailed",
                                    getName()));
  +                ok = false;
               }
           }
   
           DirContextURLStreamHandler.bind(getResources());
   
           // Restart our application event listeners and filters
  -        listenerStart();
  -        filterStart();
  +        if (ok) {
  +            if (!listenerStart())
  +                ok = false;
  +        }
  +        if (ok) {
  +            if (!filterStart())
  +                ok = false;
  +        }
   
           // Load sessions from persistent storage, if supported
           try {
  -            getManager().load();
  +            if (ok)
  +                getManager().load();
           } catch (Throwable t) {
               log(sm.getString("standardContext.managerLoad"), t);
  +            ok = false;
           }
   
           // Restart our currently defined servlets
        for (int i = 0; i < children.length; i++) {
  +            if (!ok)
  +                break;
            Wrapper wrapper = (Wrapper) children[i];
            if (wrapper instanceof Lifecycle) {
                try {
  @@ -2299,6 +2311,7 @@
                    log(sm.getString("standardContext.startingWrapper",
                                     wrapper.getName()),
                        e);
  +                    ok = false;
                }
            }
        }
  @@ -2306,8 +2319,13 @@
           DirContextURLStreamHandler.unbind();
   
        // Start accepting requests again
  -     setPaused(false);
  -     log(sm.getString("standardContext.reloadingCompleted"));
  +        if (ok) {
  +            setPaused(false);
  +            log(sm.getString("standardContext.reloadingCompleted"));
  +        } else {
  +            setAvailable(false);
  +            log(sm.getString("standardContext.reloadingFailed"));
  +        }
   
       }
   
  @@ -3031,6 +3049,8 @@
   
           if (debug >= 1)
               log("Starting");
  +        setAvailable(false);
  +        boolean ok = true;
   
           // Add missing components as necessary
           if (getResources() == null) {   // (1) Required by Loader
  @@ -3059,8 +3079,6 @@
           if (debug >= 1)
               log("Processing standard container startup");
        super.start();
  -        if (!available)
  -            return;
   
           // Reading the "catalina.useNaming" environment variable
           String useNamingProperty = System.getProperty("catalina.useNaming");
  @@ -3077,6 +3095,7 @@
               } catch (NamingException e) {
                   log(sm.getString("standardContext.namingInitFailed",
                                    getName()));
  +                ok = false;
               }
           }
   
  @@ -3087,21 +3106,32 @@
           DirContextURLStreamHandler.bind(getResources());
   
           // Configure and call application event listeners and filters
  -        listenerStart();
  -        filterStart();
  +        if (ok) {
  +            if (!listenerStart())
  +                ok = false;
  +        }
  +        if (ok) {
  +            if (!filterStart())
  +                ok = false;
  +        }
   
        // Create context attributes that will be required
  -        if (debug >= 1)
  -            log("Posting standard context attributes");
  -     postWelcomeFiles();
  +        if (ok) {
  +            if (debug >= 1)
  +                log("Posting standard context attributes");
  +            postWelcomeFiles();
  +        }
   
           // Reload sessions from persistent storage if supported
           try {
  -            if (debug >= 1)
  -                log("Loading persisted sessions");
  -            getManager().load();
  +            if (ok) {
  +                if (debug >= 1)
  +                    log("Loading persisted sessions");
  +                getManager().load();
  +            }
           } catch (Throwable t) {
               log(sm.getString("standardContext.managerLoad"), t);
  +            ok = false;
           }
   
           // Collect "load on startup" servlets that need to be initialized
  @@ -3134,20 +3164,29 @@
               ArrayList list = (ArrayList) map.get(key);
               Iterator wrappers = list.iterator();
               while (wrappers.hasNext()) {
  +                if (!ok)
  +                    break;
                   Wrapper wrapper = (Wrapper) wrappers.next();
                   try {
                       wrapper.load();
                   } catch (ServletException e) {
                       log(sm.getString("standardWrapper.loadException",
                                        getName()), e);
  +                    ok = false;
                   }
               }
           }
   
           DirContextURLStreamHandler.unbind();
   
  -        if (debug >= 1)
  -            log("Starting completed");
  +        if (ok) {
  +            if (debug >= 1)
  +                log("Starting completed");
  +            setAvailable(true);
  +        } else {
  +            log(sm.getString("standardContext.startFailed"));
  +            setAvailable(false);
  +        }
   
       }
   
  
  
  

Reply via email to