You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2003/06/21 21:59:46 UTC

cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup ExpandWar.java HostConfig.java

remm        2003/06/21 12:59:46

  Modified:    catalina/src/share/org/apache/catalina/startup
                        ExpandWar.java HostConfig.java
  Log:
  - Fix handling of invalid WARs:
    - Delete half expanded stuff in case of a failure
    - Don't print out a stack trace in case of the expected IOException
      (a warning is logged)
    - Reattempt deployment on the next check (the deployment failure
      is likely caused by a deployment attempt while the WAR copy/upload was
      in progress)
  - Properly close WARs after expanding them.
  - A few more tweaks are coming on the manager servlets side, to make them
    more user friendly, and accept more types of URLs (as long as they
    designate a WAR, of course).
  
  Revision  Changes    Path
  1.2       +46 -10    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ExpandWar.java
  
  Index: ExpandWar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ExpandWar.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ExpandWar.java	15 Jan 2003 03:40:43 -0000	1.1
  +++ ExpandWar.java	21 Jun 2003 19:59:46 -0000	1.2
  @@ -86,17 +86,20 @@
    * @author Craig R. McClanahan
    * @author Remy Maucherat
    * @author Glenn L. Nielsen
  + * @author Remy Maucherat
    * @version $Revision$
    */
   
   public class ExpandWar {
   
  +
       /**
        * The string resources for this package.
        */
       protected static final StringManager sm =
           StringManager.getManager(Constants.Package);
   
  +
       /**
        * Expand the WAR file found at the specified URL into an unpacked
        * directory structure, and return the absolute pathname to the expanded
  @@ -110,7 +113,8 @@
        * @exception IOException if an input/output error was encountered
        *  during expansion
        */
  -    public static String expand(Host host, URL war) throws IOException {
  +    public static String expand(Host host, URL war)
  +        throws IOException {
   
           int debug = 0;
           Logger logger = host.getLogger();
  @@ -137,9 +141,11 @@
           if (debug >= 1) {
               logger.log("  Proposed directory name: " + pathname);
           }
  -        return expand(host,war,pathname);
  +        return expand(host, war, pathname);
  +
       }
   
  +
       /**
        * Expand the WAR file found at the specified URL into an unpacked
        * directory structure, and return the absolute pathname to the expanded
  @@ -154,7 +160,8 @@
        * @exception IOException if an input/output error was encountered
        *  during expansion
        */
  -    public static String expand(Host host, URL war, String pathname) throws IOException {
  +    public static String expand(Host host, URL war, String pathname)
  +        throws IOException {
   
           int debug = 0;
           Logger logger = host.getLogger();
  @@ -227,9 +234,11 @@
                   input.close();
                   input = null;
               }
  -            // FIXME - Closing the JAR file messes up the class loader???
  -            //            jarFile.close();
  -            jarFile = null;
  +        } catch (IOException e) {
  +            // If something went wrong, delete expanded dir to keep things 
  +            // clean
  +            deleteDir(docBase);
  +            throw e;
           } finally {
               if (input != null) {
                   try {
  @@ -254,6 +263,7 @@
   
       }
   
  +
       /**
        * Expand the specified input stream into the specified directory, creating
        * a file named from the specified relative path.
  @@ -280,5 +290,31 @@
           output.close();
   
       }
  +
  +
  +    /**
  +     * Delete the specified directory, including all of its contents and
  +     * subdirectories recursively.
  +     *
  +     * @param dir File object representing the directory to be deleted
  +     */
  +    public static void deleteDir(File dir) {
  +
  +        String files[] = dir.list();
  +        if (files == null) {
  +            files = new String[0];
  +        }
  +        for (int i = 0; i < files.length; i++) {
  +            File file = new File(dir, files[i]);
  +            if (file.isDirectory()) {
  +                deleteDir(file);
  +            } else {
  +                file.delete();
  +            }
  +        }
  +        dir.delete();
  +
  +    }
  +
   
   }
  
  
  
  1.15      +36 -16    jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/HostConfig.java
  
  Index: HostConfig.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/HostConfig.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- HostConfig.java	15 Jun 2003 13:11:25 -0000	1.14
  +++ HostConfig.java	21 Jun 2003 19:59:46 -0000	1.15
  @@ -532,15 +532,30 @@
   
                       // Expand and deploy this application as a directory
                       log.debug(sm.getString("hostConfig.expand", files[i]));
  +                    URL url = null;
  +                    String path = null;
                       try {
  -                        URL url = new URL("jar:file:" +
  -                                          dir.getCanonicalPath() + "!/");
  -                        String path = ExpandWar.expand(host,url);
  -                        url = new URL("file:" + path);
  -                        ((Deployer) host).install(contextPath, url);
  +                        url = new URL("jar:file:" +
  +                                      dir.getCanonicalPath() + "!/");
  +                        path = ExpandWar.expand(host, url);
  +                    } catch (IOException e) {
  +                        // JAR decompression failure
  +                        log.warn(sm.getString
  +                                 ("hostConfig.expand.error", files[i]));
  +                        continue;
  +                    } catch (Throwable t) {
  +                        log.error(sm.getString
  +                                  ("hostConfig.expand.error", files[i]), t);
  +                        continue;
  +                    }
  +                    try {
  +                        if (path != null) {
  +                            url = new URL("file:" + path);
  +                            ((Deployer) host).install(contextPath, url);
  +                        }
                       } catch (Throwable t) {
  -                        log.error(sm.getString("hostConfig.expand.error", files[i]),
  -                            t);
  +                        log.error(sm.getString
  +                                  ("hostConfig.expand.error", files[i]), t);
                       }
   
                   } else {
  @@ -721,14 +736,19 @@
                                                                true);
                                   }
                               } catch (Throwable t) {
  -                                log.error(sm.getString("hostConfig.undeployJar.error",
  -                                                       files[i]), t);
  +                                log.error(sm.getString
  +                                          ("hostConfig.undeployJar.error",
  +                                           files[i]), t);
                               }
                               deployApps();
                           }
  -                        webXmlLastModified.remove(contextPath);
  -                        warLastModified.put
  -                            (files[i], new Long(dir.lastModified()));
  +                        // If deployment was successful, reset 
  +                        // the last modified values
  +                        if (host.findChild(contextPath) != null) {
  +                            webXmlLastModified.remove(contextPath);
  +                            warLastModified.put
  +                                (files[i], new Long(dir.lastModified()));
  +                        }
                       }
                   }
               }
  
  
  

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


Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup ExpandWar.java HostConfig.java

Posted by Tim Funk <fu...@joedog.org>.
You made enough changes to have your name in twice? ;)

-Tim

remm@apache.org wrote:
> remm        2003/06/21 12:59:46
>   diff -u -r1.1 -r1.2
>   --- ExpandWar.java	15 Jan 2003 03:40:43 -0000	1.1
>   +++ ExpandWar.java	21 Jun 2003 19:59:46 -0000	1.2
>   @@ -86,17 +86,20 @@
>     * @author Craig R. McClanahan
>     * @author Remy Maucherat
>     * @author Glenn L. Nielsen
>   + * @author Remy Maucherat
>     * @version $Revision$
>     */


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