Project: Jetty
Revision: 3613
Author: dyu
Date: 05 Sep 2008 04:15:07
Changes:JETTY-710 Worked around poor implementation of File.toURL()
Files:modified: /jetty/trunk/VERSION.txt (
try)
modified: /jetty/trunk/modules/server/jetty/src/main/java/org/mortbay/jetty/webapp/WebAppClassLoader.java (
try)
modified: /jetty/trunk/modules/server/jetty/src/main/java/org/mortbay/jetty/deployer/ContextDeployer.java (
try)
modified: /jetty/trunk/modules/server/jetty-start/src/main/java/org/mortbay/start/Classpath.java (
try)
modified: /jetty/trunk/modules/server/jetty/src/main/java/org/mortbay/resource/Resource.java (
try)
modified: /jetty/trunk/modules/server/jetty/src/main/java/org/mortbay/jetty/webapp/WebAppContext.java (
try)
Diff:
| ... | ...@@ -17,6 +17,7 @@ |
| 17 | 17 | + JETTY-700 unit test for unread request data |
| 18 | 18 | + JETTY-708 allow 3 scopes for jndi resources: jvm, server or webapp |
| 19 | 19 | + JETTY-709 Jetty plugin's WebAppConfig configured properties gets overridden by AbstractJettyRunMojo even when already set |
| 20 | + JETTY-710 Worked around poor implementation of File.toURL() |
| 20 | 21 | |
| 21 | 22 | jetty-7.0.0pre3 - 6 August 2008 |
| 22 | 23 | + Upgrade jsp 2.1 to SJSAS-9_1_02-B04-11_Apr_2008 |
| ... | ...@@ -29,6 +29,7 @@ |
| 29 | 29 | import org.mortbay.resource.Resource; |
| 30 | 30 | import org.mortbay.util.IO; |
| 31 | 31 | import org.mortbay.util.LazyList; |
| 32 | import org.mortbay.util.StringUtil; |
| 32 | 33 | |
| 33 | 34 | |
| 34 | 35 | /* ------------------------------------------------------------ */ |
| ... | ...@@ -204,7 +205,10 @@ |
| 204 | 205 | String fnlc=fn.getName().toLowerCase(); |
| 205 | 206 | if (fnlc.endsWith(".jar") || fnlc.endsWith(".zip")) |
| 206 | 207 | { |
| 207 | | addClassPath(fn.toString()); |
| 208 | String jar=fn.toString(); |
| 209 | jar=StringUtil.replace(jar, ",", "%2C"); |
| 210 | jar=StringUtil.replace(jar, ";", "%3B"); |
| 211 | addClassPath(jar); |
| 208 | 212 | } |
| 209 | 213 | } |
| 210 | 214 | catch (Exception ex) |
| ... | ...@@ -355,11 +355,11 @@ |
| 355 | 355 | { |
| 356 | 356 | // The config file can call any method on WebAppContext to configure |
| 357 | 357 | // the webapp being deployed. |
| 358 | | File hotDeployXmlFile=new File(filename); |
| 359 | | if (!hotDeployXmlFile.exists()) |
| 358 | Resource resource = Resource.newResource(filename); |
| 359 | if (!resource.exists()) |
| 360 | 360 | return null; |
| 361 | 361 | |
| 362 | | XmlConfiguration xmlConfiguration=new XmlConfiguration(hotDeployXmlFile.toURL()); |
| 362 | XmlConfiguration xmlConfiguration=new XmlConfiguration(resource.getURL()); |
| 363 | 363 | HashMap properties = new HashMap(); |
| 364 | 364 | properties.put("Server", _contexts.getServer()); |
| 365 | 365 | if (_configMgr!=null) |
| ... | ...@@ -16,6 +16,7 @@ |
| 16 | 16 | |
| 17 | 17 | import java.io.File; |
| 18 | 18 | import java.io.IOException; |
| 19 | import java.io.UnsupportedEncodingException; |
| 19 | 20 | import java.net.MalformedURLException; |
| 20 | 21 | import java.net.URL; |
| 21 | 22 | import java.net.URLClassLoader; |
| ... | ...@@ -108,7 +109,8 @@ |
| 108 | 109 | URL[] urls = new URL[cnt]; |
| 109 | 110 | for (int i=0; i < cnt; i++) { |
| 110 | 111 | try { |
| 111 | | urls[i] = ((File)(_elements.elementAt(i))).toURL(); |
| 112 | String u=((File)(_elements.elementAt(i))).toURL().toString(); |
| 113 | urls[i] = new URL(encodeFileURL(u)); |
| 112 | 114 | } catch (MalformedURLException e) {} |
| 113 | 115 | } |
| 114 | 116 | |
| ... | ...@@ -138,4 +140,55 @@ |
| 138 | 140 | } |
| 139 | 141 | } |
| 140 | 142 | |
| 143 | public static String encodeFileURL(String path) |
| 144 | { |
| 145 | byte[] bytes; |
| 146 | try |
| 147 | { |
| 148 | bytes=path.getBytes("utf-8"); |
| 149 | } |
| 150 | catch (UnsupportedEncodingException e) |
| 151 | { |
| 152 | bytes=path.getBytes(); |
| 153 | } |
| 154 | |
| 155 | StringBuffer buf = new StringBuffer(bytes.length*2); |
| 156 | buf.append("file:"); |
| 157 | |
| 158 | synchronized(buf) |
| 159 | { |
| 160 | for (int i=5;i<bytes.length;i++) |
| 161 | { |
| 162 | byte b=bytes[i]; |
| 163 | switch(b) |
| 164 | { |
| 165 | case '%': |
| 166 | buf.append("%25"); |
| 167 | continue; |
| 168 | case ' ': |
| 169 | buf.append("%20"); |
| 170 | continue; |
| 171 | case '/': |
| 172 | case '.': |
| 173 | case '-': |
| 174 | case '_': |
| 175 | buf.append((char)b); |
| 176 | continue; |
| 177 | default: |
| 178 | // let's be over conservative here! |
| 179 | if (Character.isJavaIdentifierPart((char)b)) |
| 180 | buf.append((char)b); |
| 181 | else |
| 182 | { |
| 183 | buf.append('%'); |
| 184 | buf.append(Integer.toHexString((0xf0&(int)b)>>4)); |
| 185 | buf.append(Integer.toHexString((0x0f&(int)b))); |
| 186 | } |
| 187 | continue; |
| 188 | } |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | return buf.toString(); |
| 193 | } |
| 141 | 194 | } |
| ... | ...@@ -148,7 +148,7 @@ |
| 148 | 148 | resource=resource.substring(2); |
| 149 | 149 | |
| 150 | 150 | File file=new File(resource).getCanonicalFile(); |
| 151 | | url=file.toURI().toURL(); |
| 151 | url=new URL(URIUtil.encodePath(file.toURL().toString())); |
| 152 | 152 | |
| 153 | 153 | URLConnection connection=url.openConnection(); |
| 154 | 154 | connection.setUseCaches(useCaches); |
| ... | ...@@ -1391,7 +1391,7 @@ |
| 1391 | 1391 | resource= newResource(_war); |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | | String tmp = resource.getURL().toExternalForm(); |
| 1394 | String tmp = URIUtil.decodePath(resource.getURL().getPath()); |
| 1395 | 1395 | if (tmp.endsWith("/")) |
| 1396 | 1396 | tmp = tmp.substring(0, tmp.length()-1); |
| 1397 | 1397 | if (tmp.endsWith("!")) |
| ... | ...@@ -1409,7 +1409,6 @@ |
| 1409 | 1409 | canonicalName.append("_"); |
| 1410 | 1410 | String contextPath = getContextPath(); |
| 1411 | 1411 | contextPath=contextPath.replace('/','_'); |
| 1412 | | contextPath=contextPath.replace('.','_'); |
| 1413 | 1412 | contextPath=contextPath.replace('\\','_'); |
| 1414 | 1413 | canonicalName.append(contextPath); |
| 1415 | 1414 | |
| ... | ...@@ -1422,6 +1421,15 @@ |
| 1422 | 1421 | String hash = Integer.toString(canonicalName.toString().hashCode(),36); |
| 1423 | 1422 | canonicalName.append("_"); |
| 1424 | 1423 | canonicalName.append(hash); |
| 1424 | |
| 1425 | // sanitize |
| 1426 | for (int i=0;i<canonicalName.length();i++) |
| 1427 | { |
| 1428 | char c=canonicalName.charAt(i); |
| 1429 | if (!Character.isJavaIdentifierPart(c)) |
| 1430 | canonicalName.setCharAt(i,'.'); |
| 1431 | } |
| 1432 | |
| 1425 | 1433 | return canonicalName.toString(); |
| 1426 | 1434 | } |
| 1427 | 1435 | } |
To list