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

(-)java/org/apache/catalina/valves/ErrorReportValve.java (-57 / +86 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
    /**
339
     * Enables/Disables server info on error pages
340
     *
341
     * @param showServerInfo
342
     */
343
    public void setShowServerInfo(boolean showServerInfo) {
344
        this.showServerInfo = showServerInfo;
345
    }
317
}
346
}

Return to bug 56383