HADOOP-14850. Read HttpServer2 resources directly from the source tree (if exists). Contributed by Elek, Marton.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e8278b02 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e8278b02 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e8278b02 Branch: refs/heads/HDFS-10467 Commit: e8278b02a45d16569fdebfd1ac36b2e648ad1e1e Parents: 1f53ae7 Author: Anu Engineer <[email protected]> Authored: Fri Sep 8 10:01:01 2017 -0700 Committer: Anu Engineer <[email protected]> Committed: Fri Sep 8 10:01:01 2017 -0700 ---------------------------------------------------------------------- .../org/apache/hadoop/http/HttpServer2.java | 30 ++++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/e8278b02/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java ---------------------------------------------------------------------- diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java index a450f66..7f1362c 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/http/HttpServer2.java @@ -27,6 +27,7 @@ import java.io.InterruptedIOException; import java.io.PrintStream; import java.net.BindException; import java.net.InetSocketAddress; +import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.util.ArrayList; @@ -993,14 +994,31 @@ public final class HttpServer2 implements FilterContainer { * Get the pathname to the webapps files. * @param appName eg "secondary" or "datanode" * @return the pathname as a URL - * @throws FileNotFoundException if 'webapps' directory cannot be found on CLASSPATH. + * @throws FileNotFoundException if 'webapps' directory cannot be found + * on CLASSPATH or in the development location. */ protected String getWebAppsPath(String appName) throws FileNotFoundException { - URL url = getClass().getClassLoader().getResource("webapps/" + appName); - if (url == null) - throw new FileNotFoundException("webapps/" + appName - + " not found in CLASSPATH"); - String urlString = url.toString(); + URL resourceUrl = null; + File webResourceDevLocation = new File("src/main/webapps", appName); + if (webResourceDevLocation.exists()) { + LOG.info("Web server is in development mode. Resources " + + "will be read from the source tree."); + try { + resourceUrl = webResourceDevLocation.getParentFile().toURI().toURL(); + } catch (MalformedURLException e) { + throw new FileNotFoundException("Mailformed URL while finding the " + + "web resource dir:" + e.getMessage()); + } + } else { + resourceUrl = + getClass().getClassLoader().getResource("webapps/" + appName); + + if (resourceUrl == null) { + throw new FileNotFoundException("webapps/" + appName + + " not found in CLASSPATH"); + } + } + String urlString = resourceUrl.toString(); return urlString.substring(0, urlString.lastIndexOf('/')); } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
