Hi,


in

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=26275

it turned out, that Tomcat suffers from a problem in Java's zip file
handling, which persists since years and most probably won't be fixed in the
next years. It also turned out, that the problem could be fixed by using
Ant's ZipFile class.

In the last days I inspected Tomcat's (4.1.30) sources for extracting WAR
files. To be honest, I find them a real mess. The design decision for
dealing with jar: and file: URL's seems to me to be severely broken,
because in the end it depends on an underlying File anyways.

Attached you find a patch, which is *not* necessary to fix bug 26275.
(Changes in ExtractWar would be sufficient.) However, I find it worth
looking at, because you'll easily see that replacing URL's with File's
reduces the code complexity quite much.

The attached patch is *not* ready for checkin, because I did not even
test it. (That's why I omitted the [PATCH] in the subject.) I just wanted a
first sign, whether it's worth to continue. If you don't like this work,
let me know and I'll return with a smaller fix for 26275.


Jochen




Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src: .classpath
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src: .project
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src: bin
diff -ubr 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/Deployer.java 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/Deployer.java
--- 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/Deployer.java  
     2004-01-25 14:23:36.000000000 +0100
+++ 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/Deployer.java
     2004-03-15 05:06:46.858592000 +0100
@@ -65,6 +65,7 @@
 package org.apache.catalina;
 
 
+import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 
@@ -117,22 +118,21 @@
     public String getName();
 
 
-    /**
-     * Install a new web application, whose web application archive is at the
-     * specified URL, into this container with the specified context path.
-     * A context path of "" (the empty string) should be used for the root
-     * application for this container.  Otherwise, the context path must
-     * start with a slash.
-     * <p>
-     * If this application is successfully installed, a ContainerEvent of type
-     * <code>INSTALL_EVENT</code> will be sent to all registered listeners,
-     * with the newly created <code>Context</code> as an argument.
-     *
-     * @param contextPath The context path to which this application should
-     *  be installed (must be unique)
-     * @param war A URL of type "jar:" that points to a WAR file, or type
-     *  "file:" that points to an unpacked directory structure containing
-     *  the web application to be installed
+    /** Install a new web application with the given context path. If this
+     * application is successfully installed, a [EMAIL PROTECTED] ContainerEvent} of
+     * type [EMAIL PROTECTED] #INSTALL_EVENT} will be sent to all registered
+     * listeners, with the newly created <code>Context</code> as an
+     * argument.
+     *
+     * @param contextPath The context path to which this application
+     *   should be installed (must be unique). A context path of ""
+     *   (the empty string) should be used for containers root
+     *   application. Otherwise, the context path must start with a
+     *   slash.
+     * @param war The web application being installed. If the location
+     *   points to a file, then it is assumed, that the file contains
+     *   a web application archive. Otherwise, the location must point
+     *   to a directory with the extracted web application.
      *
      * @exception IllegalArgumentException if the specified context path
      *  is malformed (it must be "" or start with a slash)
@@ -141,7 +141,7 @@
      * @exception IOException if an input/output error was encountered
      *  during installation
      */
-    public void install(String contextPath, URL war) throws IOException;
+    public void install(String contextPath, File war) throws IOException;
 
 
     /**
@@ -156,9 +156,10 @@
      *
      * @param config A URL that points to the context configuration file to
      *  be used for configuring the new Context
-     * @param war A URL of type "jar:" that points to a WAR file, or type
-     *  "file:" that points to an unpacked directory structure containing
-     *  the web application to be installed
+     * @param war The web application being installed. If the location
+     *   points to a file, then it is assumed, that the file contains
+     *   a web application archive. Otherwise, the location must point
+     *   to a directory with the extracted web application.
      *
      * @exception IllegalArgumentException if one of the specified URLs is
      *  null
@@ -168,7 +169,7 @@
      * @exception IOException if an input/output error was encountered
      *  during installation
      */
-    public void install(URL config, URL war) throws IOException;
+    public void install(URL config, File war) throws IOException;
 
 
     /**
diff -ubr 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHost.java
 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHost.java
--- 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHost.java
      2004-01-25 14:23:38.000000000 +0100
+++ 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHost.java
    2004-03-15 05:07:12.845960000 +0100
@@ -65,6 +65,7 @@
 package org.apache.catalina.core;
 
 
+import java.io.File;
 import java.io.IOException;
 import java.net.JarURLConnection;
 import java.net.URL;
@@ -759,31 +760,30 @@
     // ------------------------------------------------------- Deployer Methods
 
 
-    /**
-     * Install a new web application, whose web application archive is at the
-     * specified URL, into this container with the specified context path.
-     * A context path of "" (the empty string) should be used for the root
-     * application for this container.  Otherwise, the context path must
-     * start with a slash.
-     * <p>
-     * If this application is successfully installed, a ContainerEvent of type
-     * <code>INSTALL_EVENT</code> will be sent to all registered listeners,
-     * with the newly created <code>Context</code> as an argument.
-     *
-     * @param contextPath The context path to which this application should
-     *  be installed (must be unique)
-     * @param war A URL of type "jar:" that points to a WAR file, or type
-     *  "file:" that points to an unpacked directory structure containing
-     *  the web application to be installed
+    /** Install a new web application with the given context path. If this
+     * application is successfully installed, a [EMAIL PROTECTED] ContainerEvent} of
+     * type [EMAIL PROTECTED] #INSTALL_EVENT} will be sent to all registered
+     * listeners, with the newly created <code>Context</code> as an
+     * argument.
+     *
+     * @param contextPath The context path to which this application
+     *   should be installed (must be unique). A context path of ""
+     *   (the empty string) should be used for containers root
+     *   application. Otherwise, the context path must start with a
+     *   slash.
+     * @param war The web application being installed. If the location
+     *   points to a file, then it is assumed, that the file contains
+     *   a web application archive. Otherwise, the location must point
+     *   to a directory with the extracted web application.
      *
      * @exception IllegalArgumentException if the specified context path
      *  is malformed (it must be "" or start with a slash)
      * @exception IllegalStateException if the specified context path
      *  is already attached to an existing web application
      * @exception IOException if an input/output error was encountered
-     *  during install
+     *  during installation
      */
-    public void install(String contextPath, URL war) throws IOException {
+    public void install(String contextPath, File war) throws IOException {
 
         deployer.install(contextPath, war);
 
@@ -802,9 +802,10 @@
      *
      * @param config A URL that points to the context configuration file to
      *  be used for configuring the new Context
-     * @param war A URL of type "jar:" that points to a WAR file, or type
-     *  "file:" that points to an unpacked directory structure containing
-     *  the web application to be installed
+     * @param war The web application being installed. If the location
+     *   points to a file, then it is assumed, that the file contains
+     *   a web application archive. Otherwise, the location must point
+     *   to a directory with the extracted web application.
      *
      * @exception IllegalArgumentException if one of the specified URLs is
      *  null
@@ -814,10 +815,8 @@
      * @exception IOException if an input/output error was encountered
      *  during installation
      */
-    public synchronized void install(URL config, URL war) throws IOException {
-
+    public synchronized void install(URL config, File war) throws IOException {
         deployer.install(config, war);
-
     }
 
 
diff -ubr 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
--- 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
      2004-01-25 14:23:38.000000000 +0100
+++ 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/core/StandardHostDeployer.java
    2004-03-15 05:22:27.591299200 +0100
@@ -179,25 +179,21 @@
     }
 
 
-    /**
-     * Install a new web application, whose web application archive is at the
-     * specified URL, into this container with the specified context path.
-     * A context path of "" (the empty string) should be used for the root
-     * application for this container.  Otherwise, the context path must
-     * start with a slash.
-     * <p>
-     * If this application is successfully installed, a ContainerEvent of type
-     * <code>PRE_INSTALL_EVENT</code> will be sent to registered listeners
-     * before the associated Context is started, and a ContainerEvent of type
-     * <code>INSTALL_EVENT</code> will be sent to all registered listeners
-     * after the associated Context is started, with the newly created
-     * <code>Context</code> as an argument.
-     *
-     * @param contextPath The context path to which this application should
-     *  be installed (must be unique)
-     * @param war A URL of type "jar:" that points to a WAR file, or type
-     *  "file:" that points to an unpacked directory structure containing
-     *  the web application to be installed
+    /** Install a new web application with the given context path. If this
+     * application is successfully installed, a [EMAIL PROTECTED] ContainerEvent} of
+     * type [EMAIL PROTECTED] #INSTALL_EVENT} will be sent to all registered
+     * listeners, with the newly created <code>Context</code> as an
+     * argument.
+     *
+     * @param contextPath The context path to which this application
+     *   should be installed (must be unique). A context path of ""
+     *   (the empty string) should be used for containers root
+     *   application. Otherwise, the context path must start with a
+     *   slash.
+     * @param war The web application being installed. If the location
+     *   points to a file, then it is assumed, that the file contains
+     *   a web application archive. Otherwise, the location must point
+     *   to a directory with the extracted web application.
      *
      * @exception IllegalArgumentException if the specified context path
      *  is malformed (it must be "" or start with a slash)
@@ -206,7 +202,7 @@
      * @exception IOException if an input/output error was encountered
      *  during installation
      */
-    public synchronized void install(String contextPath, URL war)
+    public synchronized void install(String contextPath, File war)
         throws IOException {
 
         // Validate the format and state of our arguments
@@ -226,24 +222,14 @@
         // Calculate the document base for the new web application
         host.log(sm.getString("standardHost.installing",
                               contextPath, war.toString()));
-        String url = war.toString();
-        String docBase = null;
         boolean isWAR = false;
-        if (url.startsWith("jar:")) {
-            url = url.substring(4, url.length() - 2);
-            if (!url.toLowerCase().endsWith(".war")) {
+        if (war.isFile()) {
+            if (!war.getName().toLowerCase().endsWith(".war")) {
                 throw new IllegalArgumentException
-                    (sm.getString("standardHost.warURL", url));
+                    (sm.getString("standardHost.warURL", war.getAbsolutePath()));
             }
             isWAR = true;
         }
-        if (url.startsWith("file://"))
-            docBase = url.substring(7);
-        else if (url.startsWith("file:"))
-            docBase = url.substring(5);
-        else
-            throw new IllegalArgumentException
-                (sm.getString("standardHost.warURL", url));
 
         // Determine if directory/war to install is in the host appBase
         boolean isAppBase = false;
@@ -251,8 +237,7 @@
         if (!appBase.isAbsolute())
             appBase = new File(System.getProperty("catalina.base"),
                             host.getAppBase());
-        File contextFile = new File(docBase);
-        File baseDir = contextFile.getParentFile();
+        File baseDir = war.getParentFile();
         if (appBase.getCanonicalPath().equals(baseDir.getCanonicalPath())) {
             isAppBase = true;
         }
@@ -261,13 +246,13 @@
         // and war files from the hosts appBase
         if (!host.isDeployXML() && !isAppBase) {
             throw new IllegalArgumentException
-                (sm.getString("standardHost.installBase", url));
+                (sm.getString("standardHost.installBase", war.getAbsoluteFile()));
         }
 
         // Make sure contextPath and directory/war names match when
         // installing from the host appBase
         if (isAppBase && (host.getAutoDeploy() || host.getLiveDeploy())) {
-            String filename = contextFile.getName();
+            String filename = war.getName();
             if (isWAR) {
                 filename = filename.substring(0,filename.length()-4);
             }
@@ -283,12 +268,15 @@
         }
 
         // Expand war file if host wants wars unpacked
+        File docBase;
         if (isWAR && host.isUnpackWARs()) {
             if (contextPath.equals("")) {
                 docBase = ExpandWar.expand(host,war,"/ROOT");
             } else {
                 docBase = ExpandWar.expand(host,war,contextPath);
             }
+        } else {
+            docBase = war;
         }
 
         // Install the new web application
@@ -296,7 +284,7 @@
             Class clazz = Class.forName(host.getContextClass());
             Context context = (Context) clazz.newInstance();
             context.setPath(contextPath);
-            context.setDocBase(docBase);
+            context.setDocBase(docBase.getAbsolutePath());
             if (context instanceof Lifecycle) {
                 clazz = Class.forName(host.getConfigClass());
                 LifecycleListener listener =
@@ -317,22 +305,20 @@
 
     /**
      * <p>Install a new web application, whose context configuration file
-     * (consisting of a <code>&lt;Context&gt;</code> element) and (optional)
-     * web application archive are at the specified URLs.</p>
+     * (consisting of a <code>&lt;Context&gt;</code> element) and web
+     * application archive are at the specified URLs.</p>
      *
-     * If this application is successfully installed, a ContainerEvent of type
-     * <code>PRE_INSTALL_EVENT</code> will be sent to registered listeners
-     * before the associated Context is started, and a ContainerEvent of type
-     * <code>INSTALL_EVENT</code> will be sent to all registered listeners
-     * after the associated Context is started, with the newly created
-     * <code>Context</code> as an argument.
-     *
-     * @param config A URL that points to the context configuration descriptor
-     *  to be used for configuring the new Context
-     * @param war A URL of type "jar:" that points to a WAR file, or type
-     *  "file:" that points to an unpacked directory structure containing
-     *  the web application to be installed, or <code>null</code> to use
-     *  the <code>docBase</code> attribute from the configuration descriptor
+     * <p>If this application is successfully installed, a ContainerEvent
+     * of type <code>INSTALL_EVENT</code> will be sent to all registered
+     * listeners, with the newly created <code>Context</code> as an argument.
+     * </p>
+     *
+     * @param config A URL that points to the context configuration file to
+     *  be used for configuring the new Context
+     * @param war The web application being installed. If the location
+     *   points to a file, then it is assumed, that the file contains
+     *   a web application archive. Otherwise, the location must point
+     *   to a directory with the extracted web application.
      *
      * @exception IllegalArgumentException if one of the specified URLs is
      *  null
@@ -342,7 +328,7 @@
      * @exception IOException if an input/output error was encountered
      *  during installation
      */
-    public synchronized void install(URL config, URL war) throws IOException {
+    public synchronized void install(URL config, File war) throws IOException {
 
         // Validate the format and state of our arguments
         if (config == null)
@@ -356,20 +342,9 @@
         // Calculate the document base for the new web application (if needed)
         String docBase = null; // Optional override for value in config file
         if (war != null) {
-            String url = war.toString();
-            host.log(sm.getString("standardHost.installingWAR", url));
             // Calculate the WAR file absolute pathname
-            if (url.startsWith("jar:")) {
-                url = url.substring(4, url.length() - 2);
-            }
-            if (url.startsWith("file://"))
-                docBase = url.substring(7);
-            else if (url.startsWith("file:"))
-                docBase = url.substring(5);
-            else
-                throw new IllegalArgumentException
-                    (sm.getString("standardHost.warURL", url));
-
+            docBase = war.getAbsolutePath();
+            host.log(sm.getString("standardHost.installingWAR", docBase));
         }
 
         // Install the new web application
diff -ubr 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/HTMLManagerServlet.java
 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/HTMLManagerServlet.java
--- 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/HTMLManagerServlet.java
    2004-01-25 14:23:42.000000000 +0100
+++ 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/HTMLManagerServlet.java
  2004-03-15 05:53:40.554488000 +0100
@@ -145,7 +145,7 @@
         // Process the requested command
         if (command == null || command.equals("/")) {
         } else if (command.equals("/install")) {
-            message = install(installConfig, installPath, installWar);
+            message = install(installConfig, installPath, new File(getAppBase(), 
installWar));
         } else if (command.equals("/list")) {
         } else if (command.equals("/reload")) {
             message = reload(path);
@@ -205,7 +205,7 @@
         upload.setRepositoryPath(tempdir.getCanonicalPath());
     
         // Parse the request
-        String war = null;
+        File war = null;
         FileItem warUpload = null;
         try {
             List items = upload.parseRequest(request);
@@ -230,44 +230,26 @@
                         ("htmlManagerServlet.installUploadNoFile");
                     break;
                 }
-                war = warUpload.getName();
-                if (!war.toLowerCase().endsWith(".war")) {
+                String warName = warUpload.getName();
+                if (!warName.toLowerCase().endsWith(".war")) {
                     message = sm.getString
                         ("htmlManagerServlet.installUploadNotWar",war);
                     break;
                 }
                 // Get the filename if uploaded name includes a path
-                if (war.lastIndexOf('\\') >= 0) {
-                    war = war.substring(war.lastIndexOf('\\') + 1);
+                if (warName.lastIndexOf('\\') >= 0) {
+                    warName = warName.substring(warName.lastIndexOf('\\') + 1);
                 }
-                if (war.lastIndexOf('/') >= 0) {
-                    war = war.substring(war.lastIndexOf('/') + 1);
+                if (warName.lastIndexOf('/') >= 0) {
+                    warName = warName.substring(warName.lastIndexOf('/') + 1);
                 }
-                // Identify the appBase of the owning Host of this Context
-                // (if any)
-                String appBase = null;
-                File appBaseDir = null;
-                appBase = ((Host) context.getParent()).getAppBase();
-                appBaseDir = new File(appBase);
-                if (!appBaseDir.isAbsolute()) {
-                    appBaseDir = new File(System.getProperty("catalina.base"),
-                                          appBase);
-                }
-                File file = new File(appBaseDir,war);
-                if (file.exists()) {
+                war = new File(getAppBase(),warName);
+                if (war.exists()) {
                     message = sm.getString
-                        ("htmlManagerServlet.installUploadWarExists",war);
+                        ("htmlManagerServlet.installUploadWarExists",war.getPath());
                     break;
                 }
-                warUpload.write(file);
-                try {
-                    URL url = file.toURL();
-                    war = url.toString();
-                    war = "jar:" + war + "!/";
-                } catch(MalformedURLException e) {
-                    file.delete();
-                    throw e;
-                }
+                warUpload.write(war);
                 break;
             }
         } catch(Exception e) {
@@ -298,7 +280,7 @@
      * @param war URL of the web application archive to be installed
      * @return message String
      */
-    protected String install(String config, String path, String war) {
+    protected String install(String config, String path, File war) {
 
         StringWriter stringWriter = new StringWriter();
         PrintWriter printWriter = new PrintWriter(stringWriter);
diff -ubr 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java
 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java
--- 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java
        2004-01-25 14:23:42.000000000 +0100
+++ 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/servlets/ManagerServlet.java
      2004-03-15 05:53:09.019142400 +0100
@@ -304,6 +304,18 @@
 
     }
 
+    protected File getAppBase() {
+        File appBaseDir = null;
+        if (context.getParent() instanceof Host) {
+            String appBase = ((Host) context.getParent()).getAppBase();
+            appBaseDir = new File(appBase);
+            if (!appBaseDir.isAbsolute()) {
+                appBaseDir = new File(System.getProperty("catalina.base"),
+                                      appBase);
+            }
+        }
+        return appBaseDir;
+    }
 
     /**
      * Process a GET request for the specified resource.
@@ -343,7 +355,7 @@
         if (command == null) {
             writer.println(sm.getString("managerServlet.noCommand"));
         } else if (command.equals("/install")) {
-            install(writer, config, path, war);
+            install(writer, config, path, new File(getAppBase(), war));
         } else if (command.equals("/list")) {
             list(writer);
         } else if (command.equals("/reload")) {
@@ -552,16 +564,14 @@
 
         // Deploy this web application
         try {
-            URL warURL =
-                new URL("jar:file:" + localWar.getAbsolutePath() + "!/");
             URL xmlURL = null;
             if (localXml.exists()) {
                 xmlURL = new URL("file:" + localXml.getAbsolutePath());
             }
             if (xmlURL != null) {
-                deployer.install(xmlURL, warURL);
+                deployer.install(xmlURL, localWar);
             } else {
-                deployer.install(path, warURL);
+                deployer.install(path, localWar);
             }
         } catch (Throwable t) {
             log("ManagerServlet.deploy[" + displayPath + "]", t);
@@ -586,68 +596,38 @@
      * @param writer Writer to render results to
      * @param config URL of the context configuration file to be installed
      * @param path Context path of the application to be installed
-     * @param war URL of the web application archive to be installed
+     * @param war Web application archive to be installed
      */
     protected void install(PrintWriter writer, String config,
-                           String path, String war) {
-
-        if (war != null && war.length() == 0) {
-            war = null;
-        }
+                           String path, File war) {
 
         if (debug >= 1) {
             if (config != null && config.length() > 0) {
                 if (war != null) {
                     log("install: Installing context configuration at '" +
-                        config + "' from '" + war + "'");
+                        config + "' from '" + war.getAbsolutePath() + "'");
                 } else {
                     log("install: Installing context configuration at '" +
                         config + "'");
                 }
             } else {
                 log("install: Installing web application at '" + path +
-                    "' from '" + war + "'");
+                    "' from '" + war.getAbsolutePath() + "'");
             }
         }
 
         // See if directory/war is relative to host appBase
-        if (war != null && war.indexOf('/') < 0 ) {
+        if (war != null  &&  !war.isAbsolute()) {
             // Identify the appBase of the owning Host of this Context (if any)
-            String appBase = null;
-            File appBaseDir = null;
-            if (context.getParent() instanceof Host) {
-                appBase = ((Host) context.getParent()).getAppBase();
-                appBaseDir = new File(appBase);
-                if (!appBaseDir.isAbsolute()) {
-                    appBaseDir = new File(System.getProperty("catalina.base"),
-                                          appBase);
-                }
-                File file = new File(appBaseDir,war);
-                try {
-                    URL url = file.toURL();
-                    war = url.toString();
-                    if (war.toLowerCase().endsWith(".war")) {
-                        war = "jar:" + war + "!/";
-                    }
-                } catch(MalformedURLException e) {
-                    ;
-                }
-            }
+            war = new File(getAppBase(), war.toString());
         }
 
         if (config != null && config.length() > 0) {
-
-            if ((war != null) &&
-                (!war.startsWith("file:") && !war.startsWith("jar:"))) {
-                writer.println(sm.getString("managerServlet.invalidWar", war));
-                return;
-            }
-
             try {
                 if (war == null) {
                     deployer.install(new URL(config), null);
                 } else {
-                    deployer.install(new URL(config), new URL(war));
+                    deployer.install(new URL(config), war);
                 }
                 writer.println(sm.getString("managerServlet.configured",
                                             config));
@@ -659,33 +639,14 @@
 
         } else {
 
-            if ((war == null) ||
-                (!war.startsWith("file:") && !war.startsWith("jar:"))) {
-                writer.println(sm.getString("managerServlet.invalidWar", war));
-                return;
-            }
-
             if (path == null || path.length() == 0) {
-                int end = war.length();
-                String filename = war.toLowerCase();
-                if (filename.endsWith("!/")) {
-                    filename = filename.substring(0,filename.length()-2);
-                    end -= 2;
-                }
+                String filename = war.getName().toLowerCase();
+                int end = filename.length();
                 if (filename.endsWith(".war")) {
                     filename = filename.substring(0,filename.length()-4);
                     end -= 4;
                 }
-                if (filename.endsWith("/")) {
-                    filename = filename.substring(0,filename.length()-1);
-                    end--;
-                }
-                int beg = filename.lastIndexOf('/') + 1;
-                if (beg < 0 || end < 0 || beg >= end) {
-                    writer.println(sm.getString("managerServlet.invalidWar", war));
-                    return;
-                }
-                path = "/" + war.substring(beg,end);
+                path = "/" + filename;
                 if (path.equals("/ROOT")) {
                     path = "/";
                 }
@@ -709,7 +670,7 @@
                                       displayPath));
                     return;
                 }
-                deployer.install(path, new URL(war));
+                deployer.install(path, war);
                 writer.println(sm.getString("managerServlet.installed",
                                             displayPath));
             } catch (Throwable t) {
@@ -1191,24 +1152,12 @@
                 return;
             }
 
-            // Identify the appBase of the owning Host of this Context (if any)
-            String appBase = null;
-            File appBaseDir = null;
-            if (context.getParent() instanceof Host) {
-                appBase = ((Host) context.getParent()).getAppBase();
-                appBaseDir = new File(appBase);
-                if (!appBaseDir.isAbsolute()) {
-                    appBaseDir = new File(System.getProperty("catalina.base"),
-                                          appBase);
-                }
-            }
-
             // Validate the docBase path of this application
             String deployedPath = deployed.getCanonicalPath();
             String docBase = context.getDocBase();
             File docBaseDir = new File(docBase);
             if (!docBaseDir.isAbsolute()) {
-                docBaseDir = new File(appBaseDir, docBase);
+                docBaseDir = new File(getAppBase(), docBase);
             }
             String docBasePath = docBaseDir.getCanonicalPath();
             if (!docBasePath.startsWith(deployedPath)) {
diff -ubr 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/ExpandWar.java
 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/ExpandWar.java
--- 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/ExpandWar.java
      2004-01-25 14:23:42.000000000 +0100
+++ 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/ExpandWar.java
    2004-03-15 05:29:03.340358400 +0100
@@ -79,6 +79,8 @@
 import org.apache.catalina.Logger;
 import org.apache.catalina.core.StandardHost;
 import org.apache.catalina.util.StringManager;
+import org.apache.tools.zip.ZipEntry;
+import org.apache.tools.zip.ZipFile;
 
 /**
  * Expand out a WAR in a Host's appBase.
@@ -103,14 +105,14 @@
      * directory.
      *
      * @param host Host war is being installed for
-     * @param war URL of the web application archive to be expanded
+     * @param war Web application archive to be expanded
      *  (must start with "jar:")
      *
      * @exception IllegalArgumentException if this is not a "jar:" URL
      * @exception IOException if an input/output error was encountered
      *  during expansion
      */
-    public static String expand(Host host, URL war) throws IOException {
+    public static File expand(Host host, File war) throws IOException {
 
         int debug = 0;
         Logger logger = host.getLogger();
@@ -123,21 +125,14 @@
         if (debug >= 1) {
             logger.log("expand(" + war.toString() + ")");
         }
-        String pathname = war.toString().replace('\\', '/');
-        if (pathname.endsWith("!/")) {
-            pathname = pathname.substring(0, pathname.length() - 2);
-        }
-        int period = pathname.lastIndexOf('.');
-        if (period >= pathname.length() - 4)
-            pathname = pathname.substring(0, period);
-        int slash = pathname.lastIndexOf('/');
-        if (slash >= 0) {
-            pathname = pathname.substring(slash + 1);
-        }
+        String filename = war.getName();
+        int period = filename.lastIndexOf('.');
+        if (period >= filename.length() - 4)
+            filename = filename.substring(0, period);
         if (debug >= 1) {
-            logger.log("  Proposed directory name: " + pathname);
+            logger.log("  Proposed directory name: " + filename);
         }
-        return expand(host,war,pathname);
+        return expand(host,war,filename);
     }
 
     /**
@@ -154,7 +149,7 @@
      * @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 File expand(Host host, File war, String pathname) throws 
IOException {
 
         int debug = 0;
         Logger logger = host.getLogger();
@@ -177,7 +172,7 @@
         File docBase = new File(appBase, pathname);
         if (docBase.exists()) {
             // War file is already installed
-            return (docBase.getAbsolutePath());
+            return docBase;
         }
 
         // Create the new document base directory
@@ -188,22 +183,19 @@
         }
 
         // Expand the WAR into the new document base directory
-        JarURLConnection juc = (JarURLConnection) war.openConnection();
-        juc.setUseCaches(false);
-        JarFile jarFile = null;
+        ZipFile zipFile = new ZipFile(war);
         InputStream input = null;
         try {
-            jarFile = juc.getJarFile();
             if (debug >= 2) {
-                logger.log("  Have opened JAR file successfully");
+                logger.log("  Have opened WAR file successfully");
             }
-            Enumeration jarEntries = jarFile.entries();
+            Enumeration zipEntries = zipFile.getEntries();
             if (debug >= 2) {
                 logger.log("  Have retrieved entries enumeration");
             }
-            while (jarEntries.hasMoreElements()) {
-                JarEntry jarEntry = (JarEntry) jarEntries.nextElement();
-                String name = jarEntry.getName();
+            while (zipEntries.hasMoreElements()) {
+                ZipEntry zipEntry = (ZipEntry) zipEntries.nextElement();
+                String name = zipEntry.getName();
                 if (debug >= 2) {
                     logger.log("  Am processing entry " + name);
                 }
@@ -222,14 +214,13 @@
                 if (debug >= 2) {
                     logger.log("  Creating expanded file " + name);
                 }
-                input = jarFile.getInputStream(jarEntry);
+                input = zipFile.getInputStream(zipEntry);
                 expand(input, docBase, name);
                 input.close();
                 input = null;
             }
-            // FIXME - Closing the JAR file messes up the class loader???
-            //            jarFile.close();
-            jarFile = null;
+            zipFile.close();
+            zipFile = null;
         } finally {
             if (input != null) {
                 try {
@@ -239,18 +230,18 @@
                 }
                 input = null;
             }
-            if (jarFile != null) {
+            if (zipFile != null) {
                 try {
-                    jarFile.close();
+                    zipFile.close();
                 } catch (Throwable t) {
                     ;
                 }
-                jarFile = null;
+                zipFile = null;
             }
         }
 
         // Return the absolute path to our new document base directory
-        return (docBase.getAbsolutePath());
+        return docBase;
 
     }
 
diff -ubr 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/HostConfig.java
 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/HostConfig.java
--- 
c:\tmp\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/HostConfig.java
     2004-01-25 14:23:42.000000000 +0100
+++ 
c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/catalina/src/share/org/apache/catalina/startup/HostConfig.java
   2004-03-15 05:31:56.819809600 +0100
@@ -485,11 +485,8 @@
                     // Expand and deploy this application as a directory
                     log(sm.getString("hostConfig.expand", files[i]));
                     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);
+                        File appDir = ExpandWar.expand(host,dir.getCanonicalFile());
+                        ((Deployer) host).install(contextPath, appDir);
                     } catch (Throwable t) {
                         log(sm.getString("hostConfig.expand.error", files[i]),
                             t);
@@ -500,10 +497,7 @@
                     // Deploy the application in this WAR file
                     log(sm.getString("hostConfig.deployJar", files[i]));
                     try {
-                        URL url = new URL("file", null,
-                                          dir.getCanonicalPath());
-                        url = new URL("jar:" + url.toString() + "!/");
-                        ((Deployer) host).install(contextPath, url);
+                        ((Deployer) host).install(contextPath, 
dir.getCanonicalFile());
                     } catch (Throwable t) {
                         log(sm.getString("hostConfig.deployJar.error",
                                          files[i]), t);
@@ -555,8 +549,7 @@
                 // Deploy the application in this directory
                 log(sm.getString("hostConfig.deployDir", files[i]));
                 try {
-                    URL url = new URL("file", null, dir.getCanonicalPath());
-                    ((Deployer) host).install(contextPath, url);
+                    ((Deployer) host).install(contextPath, dir.getCanonicalFile());
                 } catch (Throwable t) {
                     log(sm.getString("hostConfig.deployDir.error", files[i]),
                         t);
@@ -627,25 +620,6 @@
 
 
     /**
-     * Expand the WAR file found at the specified URL into an unpacked
-     * directory structure, and return the absolute pathname to the expanded
-     * directory.
-     *
-     * @param war URL of the web application archive to be expanded
-     *  (must start with "jar:")
-     *
-     * @exception IllegalArgumentException if this is not a "jar:" URL
-     * @exception IOException if an input/output error was encountered
-     *  during expansion
-     */
-    protected String expand(URL war) throws IOException {
-
-        return ExpandWar.expand(host,war);
-
-    }
-
-
-    /**
      * Expand the specified input stream into the specified directory, creating
      * a file named from the specified relative path.
      *
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: activation.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: ant.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: commons-beanutils.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: commons-collections.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: commons-daemon.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: commons-digester.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: commons-fileupload-1.0.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: commons-logging-api.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: commons-modeler.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: jta.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: mail.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: mx4j-jmx.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: servlet.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: tomcat-util.jar
Only in c:\jwi\Workspace\jakarta-tomcat-4.1.30-src/lib: tyrex-1.0.1.jar


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to