412830 Error Page match ServletException then root cause
This commit is contained in:
parent
89acff6bdf
commit
d2c68bb4aa
|
@ -66,6 +66,9 @@ public class ErrorPageErrorHandler extends ErrorHandler
|
|||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
|
||||
{
|
||||
|
||||
|
||||
|
||||
String method = request.getMethod();
|
||||
if (!HttpMethod.GET.is(method) && !HttpMethod.POST.is(method) && !HttpMethod.HEAD.is(method))
|
||||
{
|
||||
|
@ -75,25 +78,26 @@ public class ErrorPageErrorHandler extends ErrorHandler
|
|||
if (_errorPages!=null)
|
||||
{
|
||||
String error_page= null;
|
||||
Class<?> exClass= (Class<?>)request.getAttribute(Dispatcher.ERROR_EXCEPTION_TYPE);
|
||||
|
||||
|
||||
Throwable th= (Throwable)request.getAttribute(Dispatcher.ERROR_EXCEPTION);
|
||||
|
||||
if (ServletException.class.equals(exClass))
|
||||
// Walk the cause hierarchy
|
||||
while (error_page == null && th != null )
|
||||
{
|
||||
Class<?> exClass=th.getClass();
|
||||
error_page= (String)_errorPages.get(exClass.getName());
|
||||
if (error_page == null)
|
||||
|
||||
// walk the inheritance hierarchy
|
||||
while (error_page == null)
|
||||
{
|
||||
Throwable th= (Throwable)request.getAttribute(Dispatcher.ERROR_EXCEPTION);
|
||||
while (th instanceof ServletException)
|
||||
th= ((ServletException)th).getRootCause();
|
||||
if (th != null)
|
||||
exClass= th.getClass();
|
||||
exClass= exClass.getSuperclass();
|
||||
if (exClass==null)
|
||||
break;
|
||||
error_page= (String)_errorPages.get(exClass.getName());
|
||||
}
|
||||
}
|
||||
|
||||
while (error_page == null && exClass != null )
|
||||
{
|
||||
error_page= (String)_errorPages.get(exClass.getName());
|
||||
exClass= exClass.getSuperclass();
|
||||
|
||||
th=(th instanceof ServletException)?((ServletException)th).getRootCause():null;
|
||||
}
|
||||
|
||||
if (error_page == null)
|
||||
|
@ -121,7 +125,7 @@ public class ErrorPageErrorHandler extends ErrorHandler
|
|||
}
|
||||
}
|
||||
|
||||
//try new servlet 3.0 global error page
|
||||
//try servlet 3.x global error page
|
||||
if (error_page == null)
|
||||
{
|
||||
error_page = _errorPages.get(GLOBAL_ERROR_PAGE);
|
||||
|
|
|
@ -538,18 +538,10 @@ public class ServletHandler extends ScopedHandler
|
|||
}
|
||||
else
|
||||
LOG.warn(th);
|
||||
while (th instanceof ServletException)
|
||||
{
|
||||
Throwable cause=((ServletException)th).getRootCause();
|
||||
if (cause==null)
|
||||
break;
|
||||
th=cause;
|
||||
}
|
||||
}
|
||||
// handle or log exception
|
||||
else if (th instanceof EofException)
|
||||
throw (EofException)th;
|
||||
|
||||
else if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.warn(request.getRequestURI(), th);
|
||||
|
@ -580,7 +572,7 @@ public class ServletHandler extends ScopedHandler
|
|||
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
else
|
||||
LOG.debug("Response already committed for handling "+th);
|
||||
LOG.debug("Response already committed",th);
|
||||
}
|
||||
catch(Error e)
|
||||
{
|
||||
|
|
|
@ -102,8 +102,8 @@ public class ErrorPageTest
|
|||
assertThat(response,Matchers.containsString("HTTP/1.1 500 Server Error"));
|
||||
assertThat(response,Matchers.containsString("ERROR_PAGE: /TestException"));
|
||||
assertThat(response,Matchers.containsString("ERROR_CODE: 500"));
|
||||
assertThat(response,Matchers.containsString("ERROR_EXCEPTION: java.lang.IllegalStateException"));
|
||||
assertThat(response,Matchers.containsString("ERROR_EXCEPTION_TYPE: class java.lang.IllegalStateException"));
|
||||
assertThat(response,Matchers.containsString("ERROR_EXCEPTION: javax.servlet.ServletException: java.lang.IllegalStateException"));
|
||||
assertThat(response,Matchers.containsString("ERROR_EXCEPTION_TYPE: class javax.servlet.ServletException"));
|
||||
assertThat(response,Matchers.containsString("ERROR_SERVLET: org.eclipse.jetty.servlet.ErrorPageTest$FailServlet-1"));
|
||||
assertThat(response,Matchers.containsString("ERROR_REQUEST_URI: /fail/exception"));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue