Issue #4529 Servlet in error page (#4530)

Added option for #4529 to control showing the servlet in an error page.
Error configuration really needs a module, but will add in 10 with a refactor.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2020-01-31 19:53:05 +01:00 committed by GitHub
parent 769cd9de69
commit b6f2fd2432
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 2 deletions

View File

@ -65,6 +65,7 @@ public class ErrorHandler extends AbstractHandler
public static final String ERROR_PAGE = "org.eclipse.jetty.server.error_page";
public static final String ERROR_CONTEXT = "org.eclipse.jetty.server.error_context";
boolean _showServlet = true;
boolean _showStacks = true;
boolean _disableStacks = false;
boolean _showMessageInTitle = true;
@ -448,13 +449,18 @@ public class ErrorHandler extends AbstractHandler
writer.printf("URI: %s%n", request.getRequestURI());
writer.printf("STATUS: %s%n", code);
writer.printf("MESSAGE: %s%n", message);
writer.printf("SERVLET: %s%n", request.getAttribute(Dispatcher.ERROR_SERVLET_NAME));
if (isShowServlet())
{
writer.printf("SERVLET: %s%n", request.getAttribute(Dispatcher.ERROR_SERVLET_NAME));
}
Throwable cause = (Throwable)request.getAttribute(Dispatcher.ERROR_EXCEPTION);
while (cause != null)
{
writer.printf("CAUSED BY %s%n", cause);
if (_showStacks && !_disableStacks)
{
cause.printStackTrace(writer);
}
cause = cause.getCause();
}
}
@ -468,7 +474,7 @@ public class ErrorHandler extends AbstractHandler
json.put("url", request.getRequestURI());
json.put("status", Integer.toString(code));
json.put("message", message);
if (servlet != null)
if (isShowServlet() && servlet != null)
{
json.put("servlet", servlet.toString());
}
@ -546,6 +552,22 @@ public class ErrorHandler extends AbstractHandler
_cacheControl = cacheControl;
}
/**
* @return True if the error page will show the Servlet that generated the error
*/
public boolean isShowServlet()
{
return _showServlet;
}
/**
* @param showServlet True if the error page will show the Servlet that generated the error
*/
public void setShowServlet(boolean showServlet)
{
_showServlet = showServlet;
}
/**
* @return True if stack traces are shown in the error pages
*/