You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by co...@eng.sun.com on 1999/11/01 21:57:53 UTC

Re: tomcat diffs

Matt wrote:

> Could someone commit these..  Rewrote windows bootstrap script to run on NT,
> catch command line args exception in ant, and catch FileNotFoundException
> when trying to upack a war file..

Hi Matt,

There are 2 problems with the WARUtil patch.
First, it seems you use a different indentation, and that makes hard to detect
the
changes.
Second, I don't understand where FileNotFoundException happened ?

Also, I don't think it is good to have messages in static util methods.

Costin

>
> RCS file:
> /home/cvspublic/jakarta-tomcat/src/share/org/apache/tomcat/util/WARUtil.java
> ,v
> retrieving revision 1.1.1.1
> diff -r1.1.1.1 WARUtil.java
> 72a73
> > import java.io.FileNotFoundException;
> 80a82,87
> >
> >     /**
> >      * The string manager for this package.
> >      */
> >     private static StringManager sm =
> StringManager.getManager(Constants.Package);
> >
> 84,90c91,97
> <       URL u = new URL(s);
> <       ZipInputStream zis = new ZipInputStream(u.openStream());
> <       ZipEntry ze = null;
> <
> <       while ((ze = zis.getNextEntry()) != null) {
> <             File f = new File(dir, ze.getName());
> <
> ---
> >     URL u = new URL(s);
> >     ZipInputStream zis = new ZipInputStream(u.openStream());
> >     ZipEntry ze = null;
> >
> >     while ((ze = zis.getNextEntry()) != null) {
> >         File f = new File(dir, ze.getName());
> >         try {
> 93,104c100,113
> <           } else {
> <               byte[] buffer = new byte[1024];
> <               int length = 0;
> <               FileOutputStream fos = new FileOutputStream(f);
> <
> <               while ((length = zis.read(buffer)) >= 0) {
> <                   fos.write(buffer, 0, length);
> <               }
> <
> <               fos.close();
> <           }
> <       }
> ---
> >             } else {
> >                 byte[] buffer = new byte[1024];
> >                 int length = 0;
> >                 FileOutputStream fos = new FileOutputStream(f);
> >
> >                 while ((length = zis.read(buffer)) >= 0) {
> >                     fos.write(buffer, 0, length);
> >                 }
> >                 fos.close();
> >             }
> >         } catch (FileNotFoundException fnfe) {
> >             System.out.println( sm.getString("WARUtil.filenotfound",
> ze.getName(), s ) );
> >         }
> >     }
> 106c115
> <       zis.close();
> ---
> >     zis.close();
> 110,116c119,125
> <       if (s.startsWith(t)) {
> <           s = s.substring(t.length());
> <       }
> <
> <       if (s.endsWith(t)) {
> <           s = s.substring(0, s.length() - t.length());
> <       }
> ---
> >     if (s.startsWith(t)) {
> >         s = s.substring(t.length());
> >     }
> >
> >     if (s.endsWith(t)) {
> >         s = s.substring(0, s.length() - t.length());
> >     }


RE: tomcat diffs

Posted by Matt Petteys <ma...@arcticmail.com>.
> Hi Matt,
>
> There are 2 problems with the WARUtil patch.
> First, it seems you use a different indentation, and that makes
> hard to detect
> the
> changes.

    public static void expand(File dir, URL war)
    throws MalformedURLException, IOException {
        String s = trim(war.getFile(), "/");
	URL u = new URL(s);
	ZipInputStream zis = new ZipInputStream(u.openStream());
	ZipEntry ze = null;

	while ((ze = zis.getNextEntry()) != null) {
-->		try {
            File f = new File(dir, ze.getName());

            if (ze.isDirectory()) {
                f.mkdirs();
	    } else {
	        byte[] buffer = new byte[1024];
		int length = 0;
	        FileOutputStream fos = new FileOutputStream(f);

		while ((length = zis.read(buffer)) >= 0) {
		    fos.write(buffer, 0, length);
		}

		fos.close();
	    }
-->		} catch (FileNotFoundException fnfe) {
-->			System.out.println("Could not find " + ze.getName() + " in " + s );
-->		}
	}

	zis.close();
    }

> Second, I don't understand where FileNotFoundException happened ?

Well, I screwed up and created a WAR file with a jar's MANIFEST file in it
and it threw this exception.  I tracked it down to this point in the code.
Without this catch, it will die w/o expanding the WAR file and print a
simple 404 out when you request files out of your WAR file.  A real pain to
debug.

Along that line, there are various places where response.sendError(404) is
called in catch clauses.  I know there isn't a logger integrated yet but
without printing out the stack there is no way to know where the errors are
occuring.  Would it make sense to print the stack out to System.out for the
time being?

mp