View | Details | Raw Unified | Return to bug 56383
Collapse All | Expand All

(-)java/org/apache/catalina/valves/mbeans-descriptors.xml (+10 lines)
Lines 194-199 Link Here
194
               type="java.lang.String"
194
               type="java.lang.String"
195
               writeable="false"/>
195
               writeable="false"/>
196
196
197
    <attribute name="showReport"
198
               description="Enables/Disables full error reports"
199
               is="true"
200
               type="boolean"/>
201
202
    <attribute name="showServerInfo"
203
               description="Enables/Disables server info on error pages"
204
               is="true"
205
               type="boolean"/>
206
197
  </mbean>
207
  </mbean>
198
208
199
  <mbean name="ExtendedAccessLogValve"
209
  <mbean name="ExtendedAccessLogValve"
(-)webapps/docs/config/valve.xml (+45 lines)
Lines 327-333 Link Here
327
327
328
</section>
328
</section>
329
329
330
<section name="Error Report Valve">
331
332
  <subsection name="Introduction">
333
334
    <p>The <strong>Error Report Valve</strong> is a simple error handler 
335
    for HTTP status codes that will generate and return HTML error pages.</p>
336
337
    <p><strong>NOTE:</strong> Disabling both showServerInfo and showReport will
338
    only return the HTTP status code and remove all CSS.</p>
339
340
  </subsection>
341
342
  <subsection name="Attributes">
343
344
    <p>The <strong>Error Report Valve</strong> supports the following
345
    configuration attributes:</p>
346
347
    <attributes>
348
349
      <attribute name="className" required="true">
350
        <p>Java class name of the implementation to use.  This MUST be set to
351
        <strong>org.apache.catalina.valves.ErrorReportValve</strong> to use the
352
        default error report valve.</p>
353
      </attribute>
354
355
      <attribute name="showReport" required="false">
356
        <p>Flag to determine if the error report is presented when an error occurs.
357
           If set to <code>false</code>, then the error report is not in 
358
           the HTML response.
359
           Default value: <code>true</code>
360
        </p>
361
      </attribute>
362
363
      <attribute name="showServerInfo" required="false">
364
        <p>Flag to determine if server information is presented when an error occurs.
365
           If set to <code>false</code>, then the server version is not returned in 
366
           the HTML response.
367
           Default value: <code>true</code>
368
        </p>
369
      </attribute>
370
371
      </attributes>
330
372
373
  </subsection>
374
375
</section>
331
<section name="Extended Access Log Valve">
376
<section name="Extended Access Log Valve">
332
377
333
  <subsection name="Introduction">
378
  <subsection name="Introduction">
(-)java/org/apache/catalina/valves/ErrorReportValve.java (-57 / +93 lines)
Lines 62-68 Link Here
62
    private static final String info =
62
    private static final String info =
63
        "org.apache.catalina.valves.ErrorReportValve/1.0";
63
        "org.apache.catalina.valves.ErrorReportValve/1.0";
64
64
65
65
    private boolean showReport = true;
66
    
67
    private boolean showServerInfo = true;
66
    // ------------------------------------------------------------- Properties
68
    // ------------------------------------------------------------- Properties
67
69
68
70
Lines 199-267 Link Here
199
201
200
        StringBuilder sb = new StringBuilder();
202
        StringBuilder sb = new StringBuilder();
201
203
202
        sb.append("<html><head><title>");
204
        sb.append("<html><head>");
203
        sb.append(ServerInfo.getServerInfo()).append(" - ");
205
        if(showServerInfo || showReport){
206
        sb.append("<title>");
207
        if(showServerInfo) {
208
            sb.append(ServerInfo.getServerInfo()).append(" - ");
209
        }
204
        sb.append(smClient.getString("errorReportValve.errorReport"));
210
        sb.append(smClient.getString("errorReportValve.errorReport"));
205
        sb.append("</title>");
211
        sb.append("</title>");        
206
        sb.append("<style><!--");
212
            sb.append("<style><!--");
207
        sb.append(org.apache.catalina.util.TomcatCSS.TOMCAT_CSS);
213
            sb.append(org.apache.catalina.util.TomcatCSS.TOMCAT_CSS);
208
        sb.append("--></style> ");
214
            sb.append("--></style> ");
215
        }
209
        sb.append("</head><body>");
216
        sb.append("</head><body>");
210
        sb.append("<h1>");
217
        sb.append("<h1>");
211
        sb.append(smClient.getString("errorReportValve.statusHeader",
218
        sb.append(smClient.getString("errorReportValve.statusHeader",
212
                               "" + statusCode, message)).append("</h1>");
219
                               "" + statusCode, message)).append("</h1>");
213
        sb.append("<HR size=\"1\" noshade=\"noshade\">");
220
        if(showReport) {
214
        sb.append("<p><b>type</b> ");
221
	        sb.append("<HR size=\"1\" noshade=\"noshade\">");
215
        if (throwable != null) {
222
	        sb.append("<p><b>type</b> ");
216
            sb.append(smClient.getString("errorReportValve.exceptionReport"));
223
	        if (throwable != null) {
217
        } else {
224
	            sb.append(smClient.getString("errorReportValve.exceptionReport"));
218
            sb.append(smClient.getString("errorReportValve.statusReport"));
225
	        } else {
226
	            sb.append(smClient.getString("errorReportValve.statusReport"));
227
	        }
228
	        sb.append("</p>");
229
	        sb.append("<p><b>");
230
	        sb.append(smClient.getString("errorReportValve.message"));
231
	        sb.append("</b> <u>");
232
	        sb.append(message).append("</u></p>");
233
	        sb.append("<p><b>");
234
	        sb.append(smClient.getString("errorReportValve.description"));
235
	        sb.append("</b> <u>");
236
	        sb.append(report);
237
	        sb.append("</u></p>");
238
	
239
	        if (throwable != null) {
240
	
241
	            String stackTrace = getPartialServletStackTrace(throwable);
242
	            sb.append("<p><b>");
243
	            sb.append(smClient.getString("errorReportValve.exception"));
244
	            sb.append("</b> <pre>");
245
	            sb.append(RequestUtil.filter(stackTrace));
246
	            sb.append("</pre></p>");
247
	
248
	            int loops = 0;
249
	            Throwable rootCause = throwable.getCause();
250
	            while (rootCause != null && (loops < 10)) {
251
	                stackTrace = getPartialServletStackTrace(rootCause);
252
	                sb.append("<p><b>");
253
	                sb.append(smClient.getString("errorReportValve.rootCause"));
254
	                sb.append("</b> <pre>");
255
	                sb.append(RequestUtil.filter(stackTrace));
256
	                sb.append("</pre></p>");
257
	                // In case root cause is somehow heavily nested
258
	                rootCause = rootCause.getCause();
259
	                loops++;
260
	            }
261
	
262
	            sb.append("<p><b>");
263
	            sb.append(smClient.getString("errorReportValve.note"));
264
	            sb.append("</b> <u>");
265
	            sb.append(smClient.getString("errorReportValve.rootCauseInLogs",
266
	            			showServerInfo?ServerInfo.getServerInfo():""));
267
	            sb.append("</u></p>");
268
	
269
	        }
219
        }
270
        }
220
        sb.append("</p>");
271
        
221
        sb.append("<p><b>");
272
        if(showServerInfo) {
222
        sb.append(smClient.getString("errorReportValve.message"));
273
            sb.append("<HR size=\"1\" noshade=\"noshade\">");
223
        sb.append("</b> <u>");
274
            sb.append("<h3>").append(ServerInfo.getServerInfo()).append("</h3>");
224
        sb.append(message).append("</u></p>");
225
        sb.append("<p><b>");
226
        sb.append(smClient.getString("errorReportValve.description"));
227
        sb.append("</b> <u>");
228
        sb.append(report);
229
        sb.append("</u></p>");
230
231
        if (throwable != null) {
232
233
            String stackTrace = getPartialServletStackTrace(throwable);
234
            sb.append("<p><b>");
235
            sb.append(smClient.getString("errorReportValve.exception"));
236
            sb.append("</b> <pre>");
237
            sb.append(RequestUtil.filter(stackTrace));
238
            sb.append("</pre></p>");
239
240
            int loops = 0;
241
            Throwable rootCause = throwable.getCause();
242
            while (rootCause != null && (loops < 10)) {
243
                stackTrace = getPartialServletStackTrace(rootCause);
244
                sb.append("<p><b>");
245
                sb.append(smClient.getString("errorReportValve.rootCause"));
246
                sb.append("</b> <pre>");
247
                sb.append(RequestUtil.filter(stackTrace));
248
                sb.append("</pre></p>");
249
                // In case root cause is somehow heavily nested
250
                rootCause = rootCause.getCause();
251
                loops++;
252
            }
253
254
            sb.append("<p><b>");
255
            sb.append(smClient.getString("errorReportValve.note"));
256
            sb.append("</b> <u>");
257
            sb.append(smClient.getString("errorReportValve.rootCauseInLogs",
258
                                   ServerInfo.getServerInfo()));
259
            sb.append("</u></p>");
260
261
        }
275
        }
262
263
        sb.append("<HR size=\"1\" noshade=\"noshade\">");
264
        sb.append("<h3>").append(ServerInfo.getServerInfo()).append("</h3>");
265
        sb.append("</body></html>");
276
        sb.append("</body></html>");
266
277
267
        try {
278
        try {
Lines 314-317 Link Here
314
        }
325
        }
315
        return trace.toString();
326
        return trace.toString();
316
    }
327
    }
328
329
    /**
330
     * Enables/Disables full error reports
331
     *
332
     * @param showReport
333
     */
334
    public void setShowReport(boolean showReport) {
335
        this.showReport = showReport;
336
    }
337
    
338
    public boolean getShowReport() {
339
        return showReport;
340
    }
341
    /**
342
     * Enables/Disables server info on error pages
343
     *
344
     * @param showServerInfo
345
     */
346
    public void setShowServerInfo(boolean showServerInfo) {
347
        this.showServerInfo = showServerInfo;
348
    }
349
    
350
    public boolean getShowServerInfo() {
351
        return showServerInfo;
352
    }
317
}
353
}

Return to bug 56383