diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java index e6752f0d0ba..3ae7a10e6ba 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/JarFileResource.java @@ -65,6 +65,19 @@ class JarFileResource extends JarResource _list=null; _entry=null; _file=null; + + if ( _jarFile != null ) + { + try + { + _jarFile.close(); + } + catch ( IOException ioe ) + { + LOG.ignore(ioe); + } + } + _jarFile=null; super.release(); } @@ -166,7 +179,7 @@ class JarFileResource extends JarResource if (jarFile!=null && _entry==null && !_directory) { // OK - we have a JarFile, lets look at the entries for our path - Enumeration e=jarFile.entries(); + Enumeration e=jarFile.entries(); while(e.hasMoreElements()) { JarEntry entry = (JarEntry) e.nextElement(); @@ -301,12 +314,11 @@ class JarFileResource extends JarResource } } - Enumeration e=jarFile.entries(); + Enumeration e=jarFile.entries(); String dir=_urlString.substring(_urlString.indexOf("!/")+2); while(e.hasMoreElements()) { - - JarEntry entry = (JarEntry) e.nextElement(); + JarEntry entry = e.nextElement(); String name=entry.getName().replace('\\','/'); if(!name.startsWith(dir) || name.length()==dir.length()) { diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java index 119facafc29..ead6b170522 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/ResourceTest.java @@ -35,8 +35,11 @@ import java.util.Date; import java.util.HashSet; import java.util.Set; import java.util.TimeZone; +import java.util.jar.JarFile; import java.util.zip.ZipFile; +import junit.framework.Assert; + import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.OS; import org.eclipse.jetty.util.IO; @@ -125,14 +128,14 @@ public class ResourceTest URI uri = file.toURI(); __userURL=uri.toURL(); - __userURL = new URL(__userURL.toString() + "src/test/java/org/eclipse/jetty/util/resource/"); - FilePermission perm = (FilePermission) __userURL.openConnection().getPermission(); - __userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar; - __relDir = "src/test/java/org/eclipse/jetty/util/resource/".replace('/', File.separatorChar); + __userURL = MavenTestingUtils.getTestResourcesDir().toURI().toURL(); + FilePermission perm = (FilePermission) __userURL.openConnection().getPermission(); + __userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar; + __relDir = "src/test/resources/".replace('/', File.separatorChar); - System.err.println("User Dir="+__userDir); - System.err.println("Rel Dir="+__relDir); - System.err.println("User URL="+__userURL); + //System.err.println("User Dir="+__userDir); + //System.err.println("Rel Dir="+__relDir); + //System.err.println("User URL="+__userURL); tmpFile=File.createTempFile("test",null).getCanonicalFile(); tmpFile.deleteOnExit(); @@ -146,15 +149,15 @@ public class ResourceTest data[i++]=new Data(__userURL,EXISTS,DIR); data[i++]=new Data(__userDir,EXISTS,DIR); data[i++]=new Data(__relDir,EXISTS,DIR); - data[i++]=new Data(__userURL+"ResourceTest.java",EXISTS,!DIR); - data[i++]=new Data(__userDir+"ResourceTest.java",EXISTS,!DIR); - data[i++]=new Data(__relDir+"ResourceTest.java",EXISTS,!DIR); + data[i++]=new Data(__userURL+"jetty-logging.properties",EXISTS,!DIR); + data[i++]=new Data(__userDir+"jetty-logging.properties",EXISTS,!DIR); + data[i++]=new Data(__relDir+"jetty-logging.properties",EXISTS,!DIR); data[i++]=new Data(__userURL+"NoName.txt",!EXISTS,!DIR); data[i++]=new Data(__userDir+"NoName.txt",!EXISTS,!DIR); data[i++]=new Data(__relDir+"NoName.txt",!EXISTS,!DIR); - data[i++]=new Data(data[rt],"ResourceTest.java",EXISTS,!DIR); - data[i++]=new Data(data[rt],"/ResourceTest.java",EXISTS,!DIR); + data[i++]=new Data(data[rt],"jetty-logging.properties",EXISTS,!DIR); + data[i++]=new Data(data[rt],"/jetty-logging.properties",EXISTS,!DIR); data[i++]=new Data(data[rt],"NoName.txt",!EXISTS,!DIR); data[i++]=new Data(data[rt],"/NoName.txt",!EXISTS,!DIR); @@ -327,15 +330,14 @@ public class ResourceTest { String s = "jar:"+__userURL+"TestData/test.zip!/subdir/numbers"; - // TODO move this into src/test/resources!!! - ZipFile zf = new ZipFile(MavenTestingUtils.getProjectFile("src/test/java/org/eclipse/jetty/util/resource/TestData/test.zip")); + ZipFile zf = new ZipFile(MavenTestingUtils.getTestResourceFile("TestData/test.zip")); long last = zf.getEntry("subdir/numbers").getTime(); Resource r = Resource.newResource(s); assertEquals(last,r.lastModified()); // Known date value inside zip } - + /* ------------------------------------------------------------ */ @Test public void testJarFileCopyToDirectoryTraversal () throws Exception diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/alphabet.txt b/jetty-util/src/test/resources/TestData/alphabet.txt similarity index 100% rename from jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/alphabet.txt rename to jetty-util/src/test/resources/TestData/alphabet.txt diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/alt.zip b/jetty-util/src/test/resources/TestData/alt.zip similarity index 100% rename from jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/alt.zip rename to jetty-util/src/test/resources/TestData/alt.zip diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/extract.zip b/jetty-util/src/test/resources/TestData/extract.zip similarity index 100% rename from jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/extract.zip rename to jetty-util/src/test/resources/TestData/extract.zip diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/test.zip b/jetty-util/src/test/resources/TestData/test.zip similarity index 100% rename from jetty-util/src/test/java/org/eclipse/jetty/util/resource/TestData/test.zip rename to jetty-util/src/test/resources/TestData/test.zip diff --git a/jetty-util/src/test/resources/TestData/test/META-INF/MANIFEST.MF b/jetty-util/src/test/resources/TestData/test/META-INF/MANIFEST.MF new file mode 100755 index 00000000000..b1f95107ebf --- /dev/null +++ b/jetty-util/src/test/resources/TestData/test/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Created-By: 1.2.2 (Sun Microsystems Inc.) + diff --git a/jetty-util/src/test/resources/TestData/test/alphabet b/jetty-util/src/test/resources/TestData/test/alphabet new file mode 100755 index 00000000000..72d007b6edb --- /dev/null +++ b/jetty-util/src/test/resources/TestData/test/alphabet @@ -0,0 +1 @@ +ABCDEFGHIJKLMNOPQRSTUVWXYZ diff --git a/jetty-util/src/test/resources/TestData/test/numbers b/jetty-util/src/test/resources/TestData/test/numbers new file mode 100755 index 00000000000..a32a4347a4e --- /dev/null +++ b/jetty-util/src/test/resources/TestData/test/numbers @@ -0,0 +1 @@ +1234567890 diff --git a/jetty-util/src/test/resources/TestData/test/subdir/alphabet b/jetty-util/src/test/resources/TestData/test/subdir/alphabet new file mode 100755 index 00000000000..72d007b6edb --- /dev/null +++ b/jetty-util/src/test/resources/TestData/test/subdir/alphabet @@ -0,0 +1 @@ +ABCDEFGHIJKLMNOPQRSTUVWXYZ diff --git a/jetty-util/src/test/resources/TestData/test/subdir/numbers b/jetty-util/src/test/resources/TestData/test/subdir/numbers new file mode 100755 index 00000000000..a32a4347a4e --- /dev/null +++ b/jetty-util/src/test/resources/TestData/test/subdir/numbers @@ -0,0 +1 @@ +1234567890 diff --git a/jetty-util/src/test/resources/TestData/test/subdir/subsubdir/alphabet b/jetty-util/src/test/resources/TestData/test/subdir/subsubdir/alphabet new file mode 100755 index 00000000000..72d007b6edb --- /dev/null +++ b/jetty-util/src/test/resources/TestData/test/subdir/subsubdir/alphabet @@ -0,0 +1 @@ +ABCDEFGHIJKLMNOPQRSTUVWXYZ diff --git a/jetty-util/src/test/resources/TestData/test/subdir/subsubdir/numbers b/jetty-util/src/test/resources/TestData/test/subdir/subsubdir/numbers new file mode 100755 index 00000000000..a32a4347a4e --- /dev/null +++ b/jetty-util/src/test/resources/TestData/test/subdir/subsubdir/numbers @@ -0,0 +1 @@ +1234567890 diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Descriptor.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Descriptor.java index 0e9d216c296..038230b4e11 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Descriptor.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Descriptor.java @@ -60,10 +60,14 @@ public abstract class Descriptor if (_root == null) { - //boolean oldValidating = _processor.getParser().getValidating(); - //_processor.getParser().setValidating(_validating); - _root = _parser.parse(_xml.getURL().toString()); - //_processor.getParser().setValidating(oldValidating); + try + { + _root = _parser.parse(_xml.getInputStream()); + } + finally + { + _xml.release(); + } } }