Repository: nifi Updated Branches: refs/heads/master 9af61d3a2 -> a274918dc
NIFI-5258 - Changed the way the servlets are created for the documentation webapp. Removed some unnecessary code. Fixed imports. This closes #2812. Signed-off-by: Andy LoPresto <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/a274918d Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/a274918d Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/a274918d Branch: refs/heads/master Commit: a274918dc54a60d6a88b4f97110abb6bcc9a2427 Parents: 9af61d3 Author: thenatog <[email protected]> Authored: Mon Jun 25 13:23:28 2018 -0400 Committer: Andy LoPresto <[email protected]> Committed: Mon Jun 25 18:22:55 2018 -0700 ---------------------------------------------------------------------- .../org/apache/nifi/web/server/JettyServer.java | 57 ++++++++++---------- 1 file changed, 30 insertions(+), 27 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/a274918d/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java index bcada35..2f93ec8 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java @@ -49,15 +49,12 @@ import org.eclipse.jetty.server.SecureRequestCustomizer; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; -import org.eclipse.jetty.server.handler.ContextHandler; -import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerList; -import org.eclipse.jetty.server.handler.ResourceHandler; import org.eclipse.jetty.server.handler.gzip.GzipHandler; +import org.eclipse.jetty.servlet.DefaultServlet; import org.eclipse.jetty.servlet.FilterHolder; -import org.eclipse.jetty.util.resource.Resource; -import org.eclipse.jetty.util.resource.ResourceCollection; +import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.webapp.Configuration; @@ -337,11 +334,10 @@ public class JettyServer implements NiFiServer { // load the documentation war webDocsContext = loadWar(webDocsWar, docsContextPath, frameworkClassLoader); - // overlay the actual documentation - final ContextHandlerCollection documentationHandlers = new ContextHandlerCollection(); - documentationHandlers.addHandler(createDocsWebApp(docsContextPath)); - documentationHandlers.addHandler(webDocsContext); - handlers.addHandler(documentationHandlers); + // add the servlets which serve the HTML documentation within the documentation web app + addDocsServlets(webDocsContext); + + handlers.addHandler(webDocsContext); // load the web error app final WebAppContext webErrorContext = loadWar(webErrorWar, "/", frameworkClassLoader); @@ -517,39 +513,46 @@ public class JettyServer implements NiFiServer { return webappContext; } - private ContextHandler createDocsWebApp(final String contextPath) { + private void addDocsServlets(WebAppContext docsContext) { try { - final ResourceHandler resourceHandler = new ResourceHandler(); - resourceHandler.setDirectoriesListed(false); - + // Load the nifi/docs directory final File docsDir = getDocsDir("docs"); - final Resource docsResource = Resource.newResource(docsDir); // load the component documentation working directory final File componentDocsDirPath = props.getComponentDocumentationWorkingDirectory(); final File workingDocsDirectory = getWorkingDocsDirectory(componentDocsDirPath); - final Resource workingDocsResource = Resource.newResource(workingDocsDirectory); + // Load the API docs final File webApiDocsDir = getWebApiDocsDir(); - final Resource webApiDocsResource = Resource.newResource(webApiDocsDir); - // create resources for both docs locations - final ResourceCollection resources = new ResourceCollection(docsResource, workingDocsResource, webApiDocsResource); - resourceHandler.setBaseResource(resources); + // Create the servlet which will serve the static resources + ServletHolder defaultHolder = new ServletHolder("default", DefaultServlet.class); + defaultHolder.setInitParameter("dirAllowed", "false"); + + ServletHolder docs = new ServletHolder("docs", DefaultServlet.class); + docs.setInitParameter("resourceBase", docsDir.getPath()); + + ServletHolder components = new ServletHolder("components", DefaultServlet.class); + components.setInitParameter("resourceBase", workingDocsDirectory.getPath()); + + ServletHolder restApi = new ServletHolder("rest-api", DefaultServlet.class); + restApi.setInitParameter("resourceBase", webApiDocsDir.getPath()); - // create the context handler - final ContextHandler handler = new ContextHandler(contextPath); - handler.setHandler(resourceHandler); + docsContext.addServlet(docs, "/html/*"); + docsContext.addServlet(components, "/components/*"); + docsContext.addServlet(restApi, "/rest-api/*"); + + docsContext.addServlet(defaultHolder, "/"); + + logger.info("Loading documents web app with context path set to " + docsContext.getContextPath()); - logger.info("Loading documents web app with context path set to " + contextPath); - return handler; } catch (Exception ex) { logger.error("Unhandled Exception in createDocsWebApp: " + ex.getMessage()); startUpFailure(ex); - return null; // required by compiler, though never be executed. } } + /** * Returns a File object for the directory containing NIFI documentation. * <p> @@ -1052,4 +1055,4 @@ public class JettyServer implements NiFiServer { @FunctionalInterface interface ServerConnectorCreator<Server, HttpConfiguration, ServerConnector> { ServerConnector create(Server server, HttpConfiguration httpConfiguration); -} \ No newline at end of file +}
