diff --git a/VERSION.txt b/VERSION.txt index 191cb0a21d9..cb7395786c3 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -16,8 +16,9 @@ jetty-7.4.3-SNAPSHOT + 349896 SCEP supports zero maxIdleTime + 349897 draft -09 websockets + 349997 MBeanContainer uses weak references - + JETTY-1342 Recreate selector in change task + 350533 Add "Origin" to the list of allowed headers in CrossOriginFilter + + 350634 Cleanup FileResource construction + + JETTY-1342 Recreate selector in change task jetty-7.4.2.v20110526 + 334443 Improve the ability to specify extra class paths using the Jetty Maven Plugin diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java index e37b223e88f..a7ef6f75b91 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/FileResource.java @@ -66,6 +66,16 @@ public class FileResource extends URLResource { return __checkAliases; } + + /* -------------------------------------------------------- */ + public FileResource(File file) throws MalformedURLException + { + super(file.toURI().toURL(),null); + + _file=file; + + fixUrlString(); + } /* -------------------------------------------------------- */ public FileResource(URL url) @@ -73,35 +83,24 @@ public class FileResource extends URLResource { super(url,null); - try - { - // Try standard API to convert URL to file. - _file =new File(new URI(url.toString())); - } - catch (Exception e) - { - Log.ignore(e); - try - { - // Assume that File.toURL produced unencoded chars. So try - // encoding them. - String file_url="file:"+URIUtil.encodePath(url.toString().substring(5)); - URI uri = new URI(file_url); - if (uri.getAuthority()==null) - _file = new File(uri); - else - _file = new File("//"+uri.getAuthority()+URIUtil.decodePath(url.getFile())); - } - catch (Exception e2) - { - Log.ignore(e2); + _file =new File(url.toURI()); - // Still can't get the file. Doh! try good old hack! - checkConnection(); - Permission perm = _connection.getPermission(); - _file = new File(perm==null?url.getFile():perm.getName()); - } - } + fixUrlString(); + } + + /* -------------------------------------------------------- */ + FileResource(URL url, URLConnection connection, File file) + { + super(url,connection); + + _file=file; + + fixUrlString(); + } + + /* -------------------------------------------------------- */ + private void fixUrlString() + { if (_file.isDirectory()) { if (!_urlString.endsWith("/")) @@ -112,16 +111,6 @@ public class FileResource extends URLResource if (_urlString.endsWith("/")) _urlString=_urlString.substring(0,_urlString.length()-1); } - - } - - /* -------------------------------------------------------- */ - FileResource(URL url, URLConnection connection, File file) - { - super(url,connection); - _file=file; - if (_file.isDirectory() && !_urlString.endsWith("/")) - _urlString=_urlString+"/"; } /* -------------------------------------------------------- */ diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java index ae3945f7376..14c2791e04b 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/resource/Resource.java @@ -160,12 +160,7 @@ public abstract class Resource implements ResourceFactory resource=resource.substring(2); File file=new File(resource).getCanonicalFile(); - url=file.toURI().toURL(); - - URLConnection connection=url.openConnection(); - connection.setUseCaches(useCaches); - FileResource fileResource= new FileResource(url,connection,file); - return fileResource; + return new FileResource(file); } catch(Exception e2) { 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 c8d46eff9e8..29c74765ff7 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 @@ -120,9 +120,11 @@ public class ResourceTest __userDir = new File(perm.getName()).getCanonicalPath() + File.separatorChar; __relDir = "src/test/java/org/eclipse/jetty/util/resource/".replace('/', File.separatorChar); + /* 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();