aboutsummaryrefslogtreecommitdiffstats
path: root/netx/net/sourceforge
diff options
context:
space:
mode:
authorAndrew Azores <[email protected]>2013-10-03 09:25:35 -0400
committerAndrew Azores <[email protected]>2013-10-03 09:25:35 -0400
commit1f5302819d8d895f979a18c1ec4a495aa05fa5d7 (patch)
tree6732935d66788b39b0b6fc7771266eac5b487f6d /netx/net/sourceforge
parentdc15299324a96ae6bb5cf601ec35ec340290fef0 (diff)
Fix regression in ResourceUrlCreator due to PR1204 patch
* netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java: (getVersionedUrl) fix regression in previous PR1204 patch. Refactor to not take Resource parameter, use instance's field instead. (uriPartToString) new method * tests/netx/unit/net/sourceforge/jnlp/cache/ResourceUrlCreatorTest.java: new tests for ResourceUrlCreator.getVersionedUrl
Diffstat (limited to 'netx/net/sourceforge')
-rw-r--r--netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java57
1 files changed, 39 insertions, 18 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java b/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java
index 0da5466..fad2d00 100644
--- a/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java
+++ b/netx/net/sourceforge/jnlp/cache/ResourceUrlCreator.java
@@ -41,8 +41,11 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
import java.util.LinkedList;
import java.util.List;
+import java.io.UnsupportedEncodingException;
import net.sourceforge.jnlp.DownloadOptions;
@@ -91,7 +94,7 @@ public class ResourceUrlCreator {
}
}
- url = getVersionedUrl(resource);
+ url = getVersionedUrl();
urls.add(url);
urls.add(resource.getLocation());
@@ -148,29 +151,47 @@ public class ResourceUrlCreator {
}
/**
- * Returns the URL for a resource, including the resource's version number in the query string
- *
- * @param resource the resource to get the url for
+ * Returns the URL for this resource, including the resource's version number in the query string
*/
- protected URL getVersionedUrl(Resource resource) {
+ protected URL getVersionedUrl() {
URL resourceUrl = resource.getLocation();
- try {
- String query = resourceUrl.getQuery(); // returns null if there was no query string
- if (resource.requestVersion != null && resource.requestVersion.isVersionId()) {
- if (query == null) {
- query = "";
- } else {
- query += "&";
- }
- query += "version-id=" + resource.requestVersion;
+ String protocol = uriPartToString(resourceUrl.getProtocol()) + "://";
+ String userInfo = uriPartToString(resourceUrl.getUserInfo());
+ if (!userInfo.isEmpty()) {
+ userInfo += "@";
+ }
+ String host = uriPartToString(resourceUrl.getHost());
+ String port;
+ if (resourceUrl.getPort() == -1) {
+ port = "";
+ } else {
+ port = ":" + String.valueOf(resourceUrl.getPort());
+ }
+ String path = uriPartToString(resourceUrl.getPath());
+ String query = uriPartToString(resourceUrl.getQuery());
+ if (!query.isEmpty()) {
+ query = "?" + query;
+ }
+ if (resource.requestVersion != null && resource.requestVersion.isVersionId()) {
+ if (!query.isEmpty()) {
+ query += "&";
+ } else {
+ query = "?" + query;
}
- URI uri = new URI(resourceUrl.getProtocol(), resourceUrl.getUserInfo(), resourceUrl.getHost(), resourceUrl.getPort(), resourceUrl.getPath(), query, null);
- return uri.toURL();
+ query += "version-id=" + resource.requestVersion;
+ }
+ try {
+ URL url = new URL(protocol + userInfo + host + port + path + query);
+ return url;
} catch (MalformedURLException e) {
return resourceUrl;
- } catch (URISyntaxException e) {
- return resourceUrl;
}
}
+ private static String uriPartToString(String part) {
+ if (part == null)
+ return "";
+ return part;
+ }
+
}