From 72e97dade5df2ec0d4abaee9ac297e668237faee Mon Sep 17 00:00:00 2001 From: Eric Charles Date: Sun, 1 Nov 2015 11:37:47 +0100 Subject: [PATCH 1/2] Allow to configure the context path of the webapp via zeppelin.server.context.path property or ZEPPELIN_CONTEXT_PATH env variable + add doc on this --- conf/zeppelin-site.xml.template | 6 ++++++ docs/docs/install/install.md | 6 ++++++ .../org/apache/zeppelin/server/ZeppelinServer.java | 10 +++++----- zeppelin-web/src/components/baseUrl/baseUrl.service.js | 2 +- .../apache/zeppelin/conf/ZeppelinConfiguration.java | 5 +++++ 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/conf/zeppelin-site.xml.template b/conf/zeppelin-site.xml.template index 90989478f97..0f44c62ad51 100755 --- a/conf/zeppelin-site.xml.template +++ b/conf/zeppelin-site.xml.template @@ -31,6 +31,12 @@ Server port. + + zeppelin.server.context.path + / + Context Path of the Web Application + + zeppelin.notebook.dir notebook diff --git a/docs/docs/install/install.md b/docs/docs/install/install.md index 03bc6f93bbb..10a11eb3a62 100644 --- a/docs/docs/install/install.md +++ b/docs/docs/install/install.md @@ -69,6 +69,12 @@ Configuration can be done by both environment variable(conf/zeppelin-env.sh) and 8080 Zeppelin server port. Note that port+1 is used for web socket + + ZEPPELIN_CONTEXT_PATH + zeppelin.server.context.path + / + Context Path of the Web Application + ZEPPELIN_NOTEBOOK_DIR zeppelin.notebook.dir diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java index a6e944da8be..c5adad6e7d4 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java @@ -85,7 +85,7 @@ public static void main(String[] args) throws Exception { jettyServer = setupJettyServer(conf); // REST api - final ServletContextHandler restApi = setupRestApiContextHandler(); + final ServletContextHandler restApi = setupRestApiContextHandler(conf); // Notebook server final ServletContextHandler notebook = setupNotebookServer(conf); @@ -168,7 +168,7 @@ private static ServletContextHandler setupNotebookServer(ZeppelinConfiguration c ServletContextHandler.SESSIONS); cxfContext.setSessionHandler(new SessionHandler()); - cxfContext.setContextPath("/"); + cxfContext.setContextPath(conf.getContextPath()); cxfContext.addServlet(servletHolder, "/ws/*"); cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*", EnumSet.allOf(DispatcherType.class)); @@ -208,7 +208,7 @@ private static SSLContext getSslContext(ZeppelinConfiguration conf) return scf.getSslContext(); } - private static ServletContextHandler setupRestApiContextHandler() { + private static ServletContextHandler setupRestApiContextHandler(ZeppelinConfiguration conf) { final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet()); cxfServletHolder.setInitParameter("javax.ws.rs.Application", ZeppelinServer.class.getName()); cxfServletHolder.setName("rest"); @@ -216,7 +216,7 @@ private static ServletContextHandler setupRestApiContextHandler() { final ServletContextHandler cxfContext = new ServletContextHandler(); cxfContext.setSessionHandler(new SessionHandler()); - cxfContext.setContextPath("/api"); + cxfContext.setContextPath(conf.getContextPath() + "/api"); cxfContext.addServlet(cxfServletHolder, "/*"); cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*", @@ -233,7 +233,7 @@ private static WebAppContext setupWebAppContext( // Development mode, read from FS // webApp.setDescriptor(warPath+"/WEB-INF/web.xml"); webApp.setResourceBase(warPath.getPath()); - webApp.setContextPath("/"); + webApp.setContextPath(conf.getContextPath()); webApp.setParentLoaderPriority(true); } else { // use packaged WAR diff --git a/zeppelin-web/src/components/baseUrl/baseUrl.service.js b/zeppelin-web/src/components/baseUrl/baseUrl.service.js index f5eb2df5970..f06eef3c4d5 100644 --- a/zeppelin-web/src/components/baseUrl/baseUrl.service.js +++ b/zeppelin-web/src/components/baseUrl/baseUrl.service.js @@ -32,7 +32,7 @@ angular.module('zeppelinWebApp').service('baseUrlSrv', function() { this.getWebsocketUrl = function() { var wsProtocol = location.protocol === 'https:' ? 'wss:' : 'ws:'; - return wsProtocol + '//' + location.hostname + ':' + this.getPort() + '/ws'; + return wsProtocol + '//' + location.hostname + ':' + this.getPort() + skipTrailingSlash(location.pathname) + '/ws'; }; this.getRestApiBase = function() { diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java index 19ddceb22de..0604455c498 100755 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java @@ -268,6 +268,10 @@ public int getServerPort() { return getInt(ConfVars.ZEPPELIN_PORT); } + public String getContextPath() { + return getString(ConfVars.ZEPPELIN_CONTEXT_PATH); + } + public String getKeyStorePath() { return getRelativeDir( String.format("%s/%s", @@ -383,6 +387,7 @@ public static enum ConfVars { ZEPPELIN_HOME("zeppelin.home", "../"), ZEPPELIN_ADDR("zeppelin.server.addr", "0.0.0.0"), ZEPPELIN_PORT("zeppelin.server.port", 8080), + ZEPPELIN_CONTEXT_PATH("zeppelin.server.context.path", "/"), ZEPPELIN_SSL("zeppelin.ssl", false), ZEPPELIN_SSL_CLIENT_AUTH("zeppelin.ssl.client.auth", false), ZEPPELIN_SSL_KEYSTORE_PATH("zeppelin.ssl.keystore.path", "keystore"), From a356166d0815b45edf94f29f27268e0aa3c90560 Mon Sep 17 00:00:00 2001 From: Eric Charles Date: Fri, 6 Nov 2015 17:18:47 +0100 Subject: [PATCH 2/2] ZEPPELIN_CONTEXT_PATH is now ZEPPELIN_SERVER_CONTEXT_PATH --- docs/docs/install/install.md | 2 +- .../java/org/apache/zeppelin/server/ZeppelinServer.java | 6 +++--- .../org/apache/zeppelin/conf/ZeppelinConfiguration.java | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/docs/install/install.md b/docs/docs/install/install.md index 10a11eb3a62..56a6b979c81 100644 --- a/docs/docs/install/install.md +++ b/docs/docs/install/install.md @@ -70,7 +70,7 @@ Configuration can be done by both environment variable(conf/zeppelin-env.sh) and Zeppelin server port. Note that port+1 is used for web socket - ZEPPELIN_CONTEXT_PATH + ZEPPELIN_SERVER_CONTEXT_PATH zeppelin.server.context.path / Context Path of the Web Application diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java index c5adad6e7d4..2816cb25371 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/server/ZeppelinServer.java @@ -168,7 +168,7 @@ private static ServletContextHandler setupNotebookServer(ZeppelinConfiguration c ServletContextHandler.SESSIONS); cxfContext.setSessionHandler(new SessionHandler()); - cxfContext.setContextPath(conf.getContextPath()); + cxfContext.setContextPath(conf.getServerContextPath()); cxfContext.addServlet(servletHolder, "/ws/*"); cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*", EnumSet.allOf(DispatcherType.class)); @@ -216,7 +216,7 @@ private static ServletContextHandler setupRestApiContextHandler(ZeppelinConfigur final ServletContextHandler cxfContext = new ServletContextHandler(); cxfContext.setSessionHandler(new SessionHandler()); - cxfContext.setContextPath(conf.getContextPath() + "/api"); + cxfContext.setContextPath(conf.getServerContextPath() + "/api"); cxfContext.addServlet(cxfServletHolder, "/*"); cxfContext.addFilter(new FilterHolder(CorsFilter.class), "/*", @@ -233,7 +233,7 @@ private static WebAppContext setupWebAppContext( // Development mode, read from FS // webApp.setDescriptor(warPath+"/WEB-INF/web.xml"); webApp.setResourceBase(warPath.getPath()); - webApp.setContextPath(conf.getContextPath()); + webApp.setContextPath(conf.getServerContextPath()); webApp.setParentLoaderPriority(true); } else { // use packaged WAR diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java index 0604455c498..17964307817 100755 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/conf/ZeppelinConfiguration.java @@ -268,8 +268,8 @@ public int getServerPort() { return getInt(ConfVars.ZEPPELIN_PORT); } - public String getContextPath() { - return getString(ConfVars.ZEPPELIN_CONTEXT_PATH); + public String getServerContextPath() { + return getString(ConfVars.ZEPPELIN_SERVER_CONTEXT_PATH); } public String getKeyStorePath() { @@ -387,7 +387,7 @@ public static enum ConfVars { ZEPPELIN_HOME("zeppelin.home", "../"), ZEPPELIN_ADDR("zeppelin.server.addr", "0.0.0.0"), ZEPPELIN_PORT("zeppelin.server.port", 8080), - ZEPPELIN_CONTEXT_PATH("zeppelin.server.context.path", "/"), + ZEPPELIN_SERVER_CONTEXT_PATH("zeppelin.server.context.path", "/"), ZEPPELIN_SSL("zeppelin.ssl", false), ZEPPELIN_SSL_CLIENT_AUTH("zeppelin.ssl.client.auth", false), ZEPPELIN_SSL_KEYSTORE_PATH("zeppelin.ssl.keystore.path", "keystore"),