ASF Bugzilla – Attachment 32591 Details for
Bug 57741
Add support for error-pages to CGIServlet
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for applying the enchancement described in the report. Adds a new init-param to the servlet configuration which will be used to trigger the error-page mechanism.
CGIServlet.java.patch (text/plain), 3.85 KB, created by
apache
on 2015-03-23 12:06:16 UTC
(
hide
)
Description:
Patch for applying the enchancement described in the report. Adds a new init-param to the servlet configuration which will be used to trigger the error-page mechanism.
Filename:
MIME Type:
Creator:
apache
Created:
2015-03-23 12:06:16 UTC
Size:
3.85 KB
patch
obsolete
>Index: java/org/apache/catalina/servlets/CGIServlet.java >=================================================================== >--- java/org/apache/catalina/servlets/CGIServlet.java (revision 1668077) >+++ java/org/apache/catalina/servlets/CGIServlet.java (working copy) >@@ -239,6 +239,13 @@ > > private static final long serialVersionUID = 1L; > >+ /** >+ * Flag for specifying whether the servlet should trigger the container's >+ * error page mechanism. For error codes, true to trigger the container's >+ * error page mechanism, false to handle the error internally. >+ */ >+ private boolean shouldTriggerErrorPage = false; >+ > /** the debugging detail level for this servlet. */ > private int debug = 0; > >@@ -329,6 +336,11 @@ > "stderrTimeout")); > } > >+ if (getServletConfig().getInitParameter("shouldTriggerErrorPage") != null) { >+ shouldTriggerErrorPage = Boolean.parseBoolean(getServletConfig().getInitParameter( >+ "shouldTriggerErrorPage")); >+ } >+ > } > > >@@ -589,7 +601,12 @@ > } > > if (!cgiEnv.isValid()) { >- res.setStatus(404); >+ handleHttpStatusCode(res, 404, shouldTriggerErrorPage); >+ >+ // no need to write to the response below since the error page mechanism will handle that >+ if (shouldTriggerErrorPage) { >+ return; >+ } > } > > if (debug >= 10) { >@@ -631,6 +648,27 @@ > > } //doGet > >+ /** >+ * Either calls HttpServletResponse.setStatus(int) or HttpServletResponse.sendError(int) >+ * based on the status code and flag provided. >+ * >+ * @param res HttpServletResponse passed in by servlet container >+ * @param statusCode HTTP status code to set for the response >+ * @param shouldTriggerErrorPage true to trigger the container's error page mechanism >+ for errors, false otherwise >+ * @throws IOException If an input or output exception occurs >+ * @throws IllegalStateException If the response was committed before this method call >+ */ >+ private static void handleHttpStatusCode(HttpServletResponse res, int statusCode, boolean shouldTriggerErrorPage) >+ throws IOException { >+ // indicate to the container that the error-page mechanism should be triggered for this error >+ if (statusCode >= 400 && shouldTriggerErrorPage) { >+ res.sendError(statusCode); >+ // otherwise, simply set the status (preventing the error-page mechanism for errors) >+ } else { >+ res.setStatus(statusCode); >+ } >+ } > > /** > * Encapsulates the CGI environment and rules to derive >@@ -1654,7 +1692,7 @@ > log("runCGI: addHeader(\"" + line + "\")"); > } > if (line.startsWith("HTTP")) { >- response.setStatus(getSCFromHttpStatusLine(line)); >+ handleHttpStatusCode(response, getSCFromHttpStatusLine(line), shouldTriggerErrorPage); > } else if (line.indexOf(":") >= 0) { > String header = > line.substring(0, line.indexOf(":")).trim(); >@@ -1661,7 +1699,8 @@ > String value = > line.substring(line.indexOf(":") + 1).trim(); > if (header.equalsIgnoreCase("status")) { >- response.setStatus(getSCFromCGIStatusHeader(value)); >+ handleHttpStatusCode(response, getSCFromCGIStatusHeader(value), >+ shouldTriggerErrorPage); > } else { > response.addHeader(header , value); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 57741
: 32591