mirror of https://github.com/apache/nifi.git
NIFI-11714 Added Error Handler to Jetty Server
- Configured Error Handler with Stack Traces disabled for NiFi and Registry Signed-off-by: Joe Gresock <jgresock@gmail.com> This closes #7447.
This commit is contained in:
parent
7c329bd2a8
commit
50b01ffd63
|
@ -48,6 +48,7 @@ import org.eclipse.jetty.server.Handler;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.ServerConnector;
|
import org.eclipse.jetty.server.ServerConnector;
|
||||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||||
|
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
||||||
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -150,6 +151,7 @@ public class JettyServer {
|
||||||
final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
|
final WebAppContext webappContext = new WebAppContext(warFile.getPath(), contextPath);
|
||||||
webappContext.setContextPath(contextPath);
|
webappContext.setContextPath(contextPath);
|
||||||
webappContext.setDisplayName(contextPath);
|
webappContext.setDisplayName(contextPath);
|
||||||
|
webappContext.setErrorHandler(getErrorHandler());
|
||||||
|
|
||||||
// instruction jetty to examine these jars for tlds, web-fragments, etc
|
// instruction jetty to examine these jars for tlds, web-fragments, etc
|
||||||
webappContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\\\.jar$|.*/[^/]*taglibs.*\\.jar$" );
|
webappContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\\\.jar$|.*/[^/]*taglibs.*\\.jar$" );
|
||||||
|
@ -189,4 +191,12 @@ public class JettyServer {
|
||||||
logger.info("Loading WAR: " + warFile.getAbsolutePath() + " with context path set to " + contextPath);
|
logger.info("Loading WAR: " + warFile.getAbsolutePath() + " with context path set to " + contextPath);
|
||||||
return webappContext;
|
return webappContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ErrorPageErrorHandler getErrorHandler() {
|
||||||
|
final ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
||||||
|
errorHandler.setShowServlet(false);
|
||||||
|
errorHandler.setShowStacks(false);
|
||||||
|
errorHandler.setShowMessageInTitle(false);
|
||||||
|
return errorHandler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||||
import org.eclipse.jetty.server.handler.HandlerList;
|
import org.eclipse.jetty.server.handler.HandlerList;
|
||||||
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
|
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
|
||||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||||
|
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
||||||
import org.eclipse.jetty.servlet.FilterHolder;
|
import org.eclipse.jetty.servlet.FilterHolder;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||||
|
@ -598,6 +599,7 @@ public class JettyServer implements NiFiServer, ExtensionUiLoader {
|
||||||
webappContext.setServerClasses(serverClasses.toArray(new String[0]));
|
webappContext.setServerClasses(serverClasses.toArray(new String[0]));
|
||||||
webappContext.setDefaultsDescriptor(WEB_DEFAULTS_XML);
|
webappContext.setDefaultsDescriptor(WEB_DEFAULTS_XML);
|
||||||
webappContext.getMimeTypes().addMimeMapping("ttf", "font/ttf");
|
webappContext.getMimeTypes().addMimeMapping("ttf", "font/ttf");
|
||||||
|
webappContext.setErrorHandler(getErrorHandler());
|
||||||
|
|
||||||
// get the temp directory for this webapp
|
// get the temp directory for this webapp
|
||||||
File tempDir = new File(props.getWebWorkingDirectory(), warFile.getName());
|
File tempDir = new File(props.getWebWorkingDirectory(), warFile.getName());
|
||||||
|
@ -1095,6 +1097,13 @@ public class JettyServer implements NiFiServer, ExtensionUiLoader {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ErrorPageErrorHandler getErrorHandler() {
|
||||||
|
final ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
||||||
|
errorHandler.setShowServlet(false);
|
||||||
|
errorHandler.setShowStacks(false);
|
||||||
|
errorHandler.setShowMessageInTitle(false);
|
||||||
|
return errorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the result of loading WARs for custom UIs.
|
* Holds the result of loading WARs for custom UIs.
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.nifi.registry.security.crypto.CryptoKeyProvider;
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
import org.eclipse.jetty.server.handler.HandlerCollection;
|
import org.eclipse.jetty.server.handler.HandlerCollection;
|
||||||
import org.eclipse.jetty.servlet.DefaultServlet;
|
import org.eclipse.jetty.servlet.DefaultServlet;
|
||||||
|
import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
|
||||||
import org.eclipse.jetty.servlet.ServletHolder;
|
import org.eclipse.jetty.servlet.ServletHolder;
|
||||||
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
|
@ -152,6 +153,7 @@ public class StandardHandlerProvider implements HandlerProvider {
|
||||||
webAppContext.setDefaultsDescriptor(DEFAULTS_DESCRIPTOR);
|
webAppContext.setDefaultsDescriptor(DEFAULTS_DESCRIPTOR);
|
||||||
webAppContext.setMaxFormContentSize(MAX_FORM_CONTENT_SIZE);
|
webAppContext.setMaxFormContentSize(MAX_FORM_CONTENT_SIZE);
|
||||||
webAppContext.setAttribute(WEB_INF_JAR_PATTERN_ATTRIBUTE, WEB_INF_JAR_PATTERN);
|
webAppContext.setAttribute(WEB_INF_JAR_PATTERN_ATTRIBUTE, WEB_INF_JAR_PATTERN);
|
||||||
|
webAppContext.setErrorHandler(getErrorHandler());
|
||||||
|
|
||||||
final File tempDirectory = getTempDirectory(workDirectory, applicationFile.getName());
|
final File tempDirectory = getTempDirectory(workDirectory, applicationFile.getName());
|
||||||
webAppContext.setTempDirectory(tempDirectory);
|
webAppContext.setTempDirectory(tempDirectory);
|
||||||
|
@ -174,6 +176,14 @@ public class StandardHandlerProvider implements HandlerProvider {
|
||||||
return applicationFiles[0];
|
return applicationFiles[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ErrorPageErrorHandler getErrorHandler() {
|
||||||
|
final ErrorPageErrorHandler errorHandler = new ErrorPageErrorHandler();
|
||||||
|
errorHandler.setShowServlet(false);
|
||||||
|
errorHandler.setShowStacks(false);
|
||||||
|
errorHandler.setShowMessageInTitle(false);
|
||||||
|
return errorHandler;
|
||||||
|
}
|
||||||
|
|
||||||
private File getTempDirectory(final File webWorkingDirectory, final String filename) {
|
private File getTempDirectory(final File webWorkingDirectory, final String filename) {
|
||||||
final File tempDirectory = new File(webWorkingDirectory, filename);
|
final File tempDirectory = new File(webWorkingDirectory, filename);
|
||||||
if (tempDirectory.isDirectory()) {
|
if (tempDirectory.isDirectory()) {
|
||||||
|
|
Loading…
Reference in New Issue