--- java/org/apache/catalina/valves/mbeans-descriptors.xml (revision 1586565) +++ java/org/apache/catalina/valves/mbeans-descriptors.xml (working copy) @@ -194,6 +194,16 @@ type="java.lang.String" writeable="false"/> + + + + +
+ + + +

The Error Report Valve is a simple error handler + for HTTP status codes that will generate and return HTML error pages.

+ +

NOTE: Disabling both showServerInfo and showReport will + only return the HTTP status code and remove all CSS.

+ +
+ + + +

The Error Report Valve supports the following + configuration attributes:

+ + + + +

Java class name of the implementation to use. This MUST be set to + org.apache.catalina.valves.ErrorReportValve to use the + default error report valve.

+
+ + +

Flag to determine if the error report is presented when an error occurs. + If set to false, then the error report is not in + the HTML response. + Default value: true +

+
+ + +

Flag to determine if server information is presented when an error occurs. + If set to false, then the server version is not returned in + the HTML response. + Default value: true +

+
+ +
+
+ +
--- java/org/apache/catalina/valves/ErrorReportValve.java (revision 1586565) +++ java/org/apache/catalina/valves/ErrorReportValve.java (working copy) @@ -62,7 +62,9 @@ private static final String info = "org.apache.catalina.valves.ErrorReportValve/1.0"; - + private boolean showReport = true; + + private boolean showServerInfo = true; // ------------------------------------------------------------- Properties @@ -199,69 +201,78 @@ StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append(ServerInfo.getServerInfo()).append(" - "); + sb.append("<html><head>"); + if(showServerInfo || showReport){ + sb.append("<title>"); + if(showServerInfo) { + sb.append(ServerInfo.getServerInfo()).append(" - "); + } sb.append(smClient.getString("errorReportValve.errorReport")); - sb.append(""); - sb.append(" "); + sb.append(""); + sb.append(" "); + } sb.append(""); sb.append("

"); sb.append(smClient.getString("errorReportValve.statusHeader", "" + statusCode, message)).append("

"); - sb.append("
"); - sb.append("

type "); - if (throwable != null) { - sb.append(smClient.getString("errorReportValve.exceptionReport")); - } else { - sb.append(smClient.getString("errorReportValve.statusReport")); + if(showReport) { + sb.append("


"); + sb.append("

type "); + if (throwable != null) { + sb.append(smClient.getString("errorReportValve.exceptionReport")); + } else { + sb.append(smClient.getString("errorReportValve.statusReport")); + } + sb.append("

"); + sb.append("

"); + sb.append(smClient.getString("errorReportValve.message")); + sb.append(" "); + sb.append(message).append("

"); + sb.append("

"); + sb.append(smClient.getString("errorReportValve.description")); + sb.append(" "); + sb.append(report); + sb.append("

"); + + if (throwable != null) { + + String stackTrace = getPartialServletStackTrace(throwable); + sb.append("

"); + sb.append(smClient.getString("errorReportValve.exception")); + sb.append("

");
+	            sb.append(RequestUtil.filter(stackTrace));
+	            sb.append("

"); + + int loops = 0; + Throwable rootCause = throwable.getCause(); + while (rootCause != null && (loops < 10)) { + stackTrace = getPartialServletStackTrace(rootCause); + sb.append("

"); + sb.append(smClient.getString("errorReportValve.rootCause")); + sb.append("

");
+	                sb.append(RequestUtil.filter(stackTrace));
+	                sb.append("

"); + // In case root cause is somehow heavily nested + rootCause = rootCause.getCause(); + loops++; + } + + sb.append("

"); + sb.append(smClient.getString("errorReportValve.note")); + sb.append(" "); + sb.append(smClient.getString("errorReportValve.rootCauseInLogs", + showServerInfo?ServerInfo.getServerInfo():"")); + sb.append("

"); + + } } - sb.append("

"); - sb.append("

"); - sb.append(smClient.getString("errorReportValve.message")); - sb.append(" "); - sb.append(message).append("

"); - sb.append("

"); - sb.append(smClient.getString("errorReportValve.description")); - sb.append(" "); - sb.append(report); - sb.append("

"); - - if (throwable != null) { - - String stackTrace = getPartialServletStackTrace(throwable); - sb.append("

"); - sb.append(smClient.getString("errorReportValve.exception")); - sb.append("

");
-            sb.append(RequestUtil.filter(stackTrace));
-            sb.append("

"); - - int loops = 0; - Throwable rootCause = throwable.getCause(); - while (rootCause != null && (loops < 10)) { - stackTrace = getPartialServletStackTrace(rootCause); - sb.append("

"); - sb.append(smClient.getString("errorReportValve.rootCause")); - sb.append("

");
-                sb.append(RequestUtil.filter(stackTrace));
-                sb.append("

"); - // In case root cause is somehow heavily nested - rootCause = rootCause.getCause(); - loops++; - } - - sb.append("

"); - sb.append(smClient.getString("errorReportValve.note")); - sb.append(" "); - sb.append(smClient.getString("errorReportValve.rootCauseInLogs", - ServerInfo.getServerInfo())); - sb.append("

"); - + + if(showServerInfo) { + sb.append("
"); + sb.append("

").append(ServerInfo.getServerInfo()).append("

"); } - - sb.append("
"); - sb.append("

").append(ServerInfo.getServerInfo()).append("

"); sb.append(""); try { @@ -314,4 +325,29 @@ } return trace.toString(); } + + /** + * Enables/Disables full error reports + * + * @param showReport + */ + public void setShowReport(boolean showReport) { + this.showReport = showReport; + } + + public boolean getShowReport() { + return showReport; + } + /** + * Enables/Disables server info on error pages + * + * @param showServerInfo + */ + public void setShowServerInfo(boolean showServerInfo) { + this.showServerInfo = showServerInfo; + } + + public boolean getShowServerInfo() { + return showServerInfo; + } }