mirror of https://github.com/apache/nifi.git
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 <alopresto@apache.org>
This commit is contained in:
parent
9af61d3a2d
commit
a274918dc5
|
@ -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");
|
||||
|
||||
// create the context handler
|
||||
final ContextHandler handler = new ContextHandler(contextPath);
|
||||
handler.setHandler(resourceHandler);
|
||||
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());
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue