Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2016-01-27 13:55:00 -0500
committerJoakim Erdfelt2016-01-27 13:55:00 -0500
commit1aef09acc2ad6fad040c56e6826a83e9749fdedd (patch)
tree99936faba9b9b11bdd5eacb4c7495297d29d1460
parente3dd0cb83be2df2470595b272dc740a538b7c8f1 (diff)
downloadorg.eclipse.jetty.project-1aef09acc2ad6fad040c56e6826a83e9749fdedd.tar.gz
org.eclipse.jetty.project-1aef09acc2ad6fad040c56e6826a83e9749fdedd.tar.xz
org.eclipse.jetty.project-1aef09acc2ad6fad040c56e6826a83e9749fdedd.zip
486604 - Add debug logging of ErrorPageErrorHandler logic
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java6
-rw-r--r--jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java52
2 files changed, 52 insertions, 6 deletions
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
index 016c57885a..1106826bbc 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ErrorHandler.java
@@ -39,7 +39,6 @@ import org.eclipse.jetty.server.Response;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.ByteArrayISO8859Writer;
-import org.eclipse.jetty.util.Jetty;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -101,6 +100,11 @@ public class ErrorHandler extends AbstractHandler
return;
}
}
+ } else {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("No Error Page mapping for request({} {}) (using default)",request.getMethod(),request.getRequestURI());
+ }
}
}
diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java
index 976fb34ac2..f7ad40d232 100644
--- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java
+++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ErrorPageErrorHandler.java
@@ -30,17 +30,20 @@ import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.server.Dispatcher;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
+import org.eclipse.jetty.util.log.Log;
+import org.eclipse.jetty.util.log.Logger;
/* ------------------------------------------------------------ */
/** Error Page Error Handler
*
* An ErrorHandler that maps exceptions and status codes to URIs for dispatch using
* the internal ERROR style of dispatch.
- *
*/
public class ErrorPageErrorHandler extends ErrorHandler implements ErrorHandler.ErrorPageMapper
{
public final static String GLOBAL_ERROR_PAGE = "org.eclipse.jetty.server.error_page.global";
+ private static final Logger LOG = Log.getLogger(ErrorPageErrorHandler.class);
+ enum PageLookupTechnique{ THROWABLE, STATUS_CODE, GLOBAL }
protected ServletContext _servletContext;
private final Map<String,String> _errorPages= new HashMap<String,String>(); // code or exception to URL
@@ -56,11 +59,15 @@ public class ErrorPageErrorHandler extends ErrorHandler implements ErrorHandler.
{
String error_page= null;
+ PageLookupTechnique pageSource = null;
+
Throwable th= (Throwable)request.getAttribute(Dispatcher.ERROR_EXCEPTION);
// Walk the cause hierarchy
while (error_page == null && th != null )
{
+ pageSource = PageLookupTechnique.THROWABLE;
+
Class<?> exClass=th.getClass();
error_page= (String)_errorPages.get(exClass.getName());
@@ -76,13 +83,17 @@ public class ErrorPageErrorHandler extends ErrorHandler implements ErrorHandler.
th=(th instanceof ServletException)?((ServletException)th).getRootCause():null;
}
+ Integer errorStatusCode = null;
+
if (error_page == null)
{
+ pageSource = PageLookupTechnique.STATUS_CODE;
+
// look for an exact code match
- Integer code=(Integer)request.getAttribute(Dispatcher.ERROR_STATUS_CODE);
- if (code!=null)
+ errorStatusCode = (Integer)request.getAttribute(Dispatcher.ERROR_STATUS_CODE);
+ if (errorStatusCode!=null)
{
- error_page= (String)_errorPages.get(Integer.toString(code));
+ error_page= (String)_errorPages.get(Integer.toString(errorStatusCode));
// if still not found
if ((error_page == null) && (_errorPageList != null))
@@ -91,7 +102,7 @@ public class ErrorPageErrorHandler extends ErrorHandler implements ErrorHandler.
for (int i = 0; i < _errorPageList.size(); i++)
{
ErrorCodeRange errCode = (ErrorCodeRange) _errorPageList.get(i);
- if (errCode.isInRange(code))
+ if (errCode.isInRange(errorStatusCode))
{
error_page = errCode.getUri();
break;
@@ -103,7 +114,38 @@ public class ErrorPageErrorHandler extends ErrorHandler implements ErrorHandler.
//try servlet 3.x global error page
if (error_page == null)
+ {
+ pageSource = PageLookupTechnique.GLOBAL;
error_page = _errorPages.get(GLOBAL_ERROR_PAGE);
+ }
+
+ if (LOG.isDebugEnabled())
+ {
+ StringBuilder dbg = new StringBuilder();
+ dbg.append("getErrorPage(");
+ dbg.append(request.getMethod()).append(' ');
+ dbg.append(request.getRequestURI());
+ dbg.append(") => error_page=").append(error_page);
+ switch (pageSource)
+ {
+ case THROWABLE:
+ dbg.append(" (from Throwable ");
+ dbg.append(th.getClass().getName());
+ dbg.append(')');
+ LOG.debug(dbg.toString(),th);
+ break;
+ case STATUS_CODE:
+ dbg.append(" (from status code ");
+ dbg.append(errorStatusCode);
+ dbg.append(')');
+ LOG.debug(dbg.toString());
+ break;
+ case GLOBAL:
+ dbg.append(" (from global default)");
+ LOG.debug(dbg.toString());
+ break;
+ }
+ }
return error_page;
}

Back to the top