annotate src/org/eclipse/jetty/server/handler/ErrorHandler.java @ 856:ea1768c00d03

remove NCSARequestLog and RequestLog
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 21 Sep 2016 00:19:26 -0600
parents 0048a843297a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 // ------------------------------------------------------------------------
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 // All rights reserved. This program and the accompanying materials
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 // are made available under the terms of the Eclipse Public License v1.0
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 // and Apache License v2.0 which accompanies this distribution.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 // The Eclipse Public License is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 // http://www.eclipse.org/legal/epl-v10.html
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
12 // The Apache License v2.0 is available at
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
13 // http://www.opensource.org/licenses/apache2.0.php
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
14 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
15 // You may elect to redistribute this code under either of these licenses.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
16 // ========================================================================
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
17 //
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
18
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19 package org.eclipse.jetty.server.handler;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
20
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 import java.io.IOException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 import java.io.PrintWriter;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 import java.io.StringWriter;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 import java.io.Writer;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
25
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 import javax.servlet.ServletException;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
27 import javax.servlet.http.HttpServletRequest;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
28 import javax.servlet.http.HttpServletResponse;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
29
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
30 import org.eclipse.jetty.http.HttpHeaders;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
31 import org.eclipse.jetty.http.HttpMethods;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
32 import org.eclipse.jetty.http.HttpStatus;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
33 import org.eclipse.jetty.http.MimeTypes;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
34 import org.eclipse.jetty.server.AbstractHttpConnection;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
35 import org.eclipse.jetty.server.Request;
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
36 import org.eclipse.jetty.util.ByteArrayISO8859Writer;
820
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
37 import org.slf4j.Logger;
8e9db0bbf4f9 remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents: 802
diff changeset
38 import org.slf4j.LoggerFactory;
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
39
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
40 /* ------------------------------------------------------------ */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
41 /** Handler for Error pages
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
42 * An ErrorHandler is registered with {@link ContextHandler#setErrorHandler(ErrorHandler)} or
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
43 * {@link org.eclipse.jetty.server.Server#addBean(Object)}.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
44 * It is called by the HttpResponse.sendError method to write a error page.
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 *
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 */
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47 public class ErrorHandler extends AbstractHandler
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 {
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
49 private static final Logger LOG = LoggerFactory.getLogger(ErrorHandler.class);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
50 public final static String ERROR_PAGE="org.eclipse.jetty.server.error_page";
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
51
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
52 boolean _showStacks=true;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
53 boolean _showMessageInTitle=true;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
54 String _cacheControl="must-revalidate,no-cache,no-store";
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
55
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
56 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
57 /*
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
58 * @see org.eclipse.jetty.server.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
59 */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
60 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
61 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
62 AbstractHttpConnection connection = AbstractHttpConnection.getCurrentConnection();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
63 String method = request.getMethod();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
64 if(!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD))
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
65 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
66 connection.getRequest().setHandled(true);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
67 return;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
68 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
69
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
70 connection.getRequest().setHandled(true);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
71 response.setContentType(MimeTypes.TEXT_HTML_8859_1);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
72 if (_cacheControl!=null)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
73 response.setHeader(HttpHeaders.CACHE_CONTROL, _cacheControl);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
74 ByteArrayISO8859Writer writer= new ByteArrayISO8859Writer(4096);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
75 handleErrorPage(request, writer, connection.getResponse().getStatus(), connection.getResponse().getReason());
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
76 writer.flush();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
77 response.setContentLength(writer.size());
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
78 writer.writeTo(response.getOutputStream());
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
79 writer.destroy();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
80 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
81
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
82 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
83 protected void handleErrorPage(HttpServletRequest request, Writer writer, int code, String message)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
84 throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
85 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
86 writeErrorPage(request, writer, code, message, _showStacks);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
87 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
88
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
89 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
90 protected void writeErrorPage(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
91 throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
92 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
93 if (message == null)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
94 message=HttpStatus.getMessage(code);
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
95
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
96 writer.write("<html>\n<head>\n");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
97 writeErrorPageHead(request,writer,code,message);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
98 writer.write("</head>\n<body>");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
99 writeErrorPageBody(request,writer,code,message,showStacks);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
100 writer.write("\n</body>\n</html>\n");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
101 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
102
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
103 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
104 protected void writeErrorPageHead(HttpServletRequest request, Writer writer, int code, String message)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
105 throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
106 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
107 writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\"/>\n");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
108 writer.write("<title>Error ");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
109 writer.write(Integer.toString(code));
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
110
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
111 if (_showMessageInTitle)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
112 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
113 writer.write(' ');
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
114 write(writer,message);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
115 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
116 writer.write("</title>\n");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
117 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
118
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
119 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
120 protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
121 throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
122 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
123 String uri= request.getRequestURI();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
124
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
125 writeErrorPageMessage(request,writer,code,message,uri);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
126 if (showStacks)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
127 writeErrorPageStacks(request,writer);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
128 writer.write("<hr /><i><small>Powered by Jetty://</small></i>");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
129 for (int i= 0; i < 20; i++)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
130 writer.write("<br/> \n");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
131 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
132
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
133 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
134 protected void writeErrorPageMessage(HttpServletRequest request, Writer writer, int code, String message,String uri)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
135 throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
136 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
137 writer.write("<h2>HTTP ERROR ");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
138 writer.write(Integer.toString(code));
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
139 writer.write("</h2>\n<p>Problem accessing ");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
140 write(writer,uri);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
141 writer.write(". Reason:\n<pre> ");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
142 write(writer,message);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
143 writer.write("</pre></p>");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
144 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
145
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
146 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
147 protected void writeErrorPageStacks(HttpServletRequest request, Writer writer)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
148 throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
149 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
150 Throwable th = (Throwable)request.getAttribute("javax.servlet.error.exception");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
151 while(th!=null)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
152 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
153 writer.write("<h3>Caused by:</h3><pre>");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
154 StringWriter sw = new StringWriter();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
155 PrintWriter pw = new PrintWriter(sw);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
156 th.printStackTrace(pw);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
157 pw.flush();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
158 write(writer,sw.getBuffer().toString());
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
159 writer.write("</pre>\n");
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
160
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
161 th =th.getCause();
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
162 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
163 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
164
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
165
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
166 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
167 /** Get the cacheControl.
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
168 * @return the cacheControl header to set on error responses.
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
169 */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
170 public String getCacheControl()
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
171 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
172 return _cacheControl;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
173 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
174
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
175 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
176 /** Set the cacheControl.
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
177 * @param cacheControl the cacheControl header to set on error responses.
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
178 */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
179 public void setCacheControl(String cacheControl)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
180 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
181 _cacheControl = cacheControl;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
182 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
183
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
184 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
185 /**
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
186 * @return True if stack traces are shown in the error pages
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
187 */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
188 public boolean isShowStacks()
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
189 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
190 return _showStacks;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
191 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
192
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
193 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
194 /**
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
195 * @param showStacks True if stack traces are shown in the error pages
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
196 */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
197 public void setShowStacks(boolean showStacks)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
198 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
199 _showStacks = showStacks;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
200 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
201
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
202 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
203 /**
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
204 * @param showMessageInTitle if true, the error message appears in page title
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
205 */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
206 public void setShowMessageInTitle(boolean showMessageInTitle)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
207 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
208 _showMessageInTitle = showMessageInTitle;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
209 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
210
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
211
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
212 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
213 public boolean getShowMessageInTitle()
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
214 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
215 return _showMessageInTitle;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
216 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
217
821
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
218 /* ------------------------------------------------------------ */
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
219 protected void write(Writer writer,String string)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
220 throws IOException
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
221 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
222 if (string==null)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
223 return;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
224
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
225 for (int i=0;i<string.length();i++)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
226 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
227 char c=string.charAt(i);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
228
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
229 switch(c)
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
230 {
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
231 case '&' :
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
232 writer.write("&amp;");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
233 break;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
234 case '<' :
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
235 writer.write("&lt;");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
236 break;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
237 case '>' :
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
238 writer.write("&gt;");
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
239 break;
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
240
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
241 default:
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
242 if (Character.isISOControl(c) && !Character.isWhitespace(c))
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
243 writer.write('?');
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
244 else
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
245 writer.write(c);
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
246 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
247 }
292f2e31ab41 remove ErrorHandler.ErrorPageMapper
Franklin Schmidt <fschmidt@gmail.com>
parents: 820
diff changeset
248 }
802
3428c60d7cfc replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
249 }