You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by al...@apache.org on 2018/07/12 01:31:17 UTC

[09/10] nifi git commit: NIFI-5258 - Changed the way the servlets are created for the documentation webapp. Removed some unnecessary code. Fixed imports.

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 <al...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/d326edb2
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/d326edb2
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/d326edb2

Branch: refs/heads/support/nifi-1.7.x
Commit: d326edb25765c02e66fb16f4b52c47c3bc444f00
Parents: f4b2aae
Author: thenatog <th...@gmail.com>
Authored: Mon Jun 25 13:23:28 2018 -0400
Committer: Andy LoPresto <al...@apache.org>
Committed: Wed Jul 11 18:30:06 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/d326edb2/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
+}