Revert "CLOUDSTACK-6940:Templates cannot be downloaded from URLs without"
This reverts commit 569e94908b6fa471f2f72578e1ff21f3fa7c6a4e. Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a8316de7 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a8316de7 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a8316de7 Branch: refs/heads/master Commit: a8316de725db149aec8545bb5b0dfb7c71be2824 Parents: af37743 Author: Min Chen <min.c...@citrix.com> Authored: Mon Aug 11 17:03:53 2014 -0700 Committer: Min Chen <min.c...@citrix.com> Committed: Tue Aug 12 11:43:08 2014 -0700 ---------------------------------------------------------------------- .../cloud/template/HypervisorTemplateAdapter.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a8316de7/server/src/com/cloud/template/HypervisorTemplateAdapter.java ---------------------------------------------------------------------- diff --git a/server/src/com/cloud/template/HypervisorTemplateAdapter.java b/server/src/com/cloud/template/HypervisorTemplateAdapter.java index 9b17c30..419a501 100755 --- a/server/src/com/cloud/template/HypervisorTemplateAdapter.java +++ b/server/src/com/cloud/template/HypervisorTemplateAdapter.java @@ -16,6 +16,8 @@ // under the License. package com.cloud.template; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -122,6 +124,20 @@ public class HypervisorTemplateAdapter extends TemplateAdapterBase { public TemplateProfile prepare(RegisterTemplateCmd cmd) throws ResourceAllocationException { TemplateProfile profile = super.prepare(cmd); String url = profile.getUrl(); + String path = null; + try { + URL str = new URL(url); + path = str.getPath(); + } catch (MalformedURLException ex) { + throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is invalid"); + } + + try { + checkFormat(cmd.getFormat(), url); + } catch (InvalidParameterValueException ex) { + checkFormat(cmd.getFormat(), path); + } + UriUtils.validateUrl(url); profile.setUrl(url); // Check that the resource limit for secondary storage won't be exceeded