// we are in handleRequest for the "default" error handler
log("ERROR: can't find default error handler, or error in default error page", t);
}
String errorPath=null;
Handler errorServlet=null;
// Scan the exception's inheritance tree looking for a rule
// that this type of exception should be forwarded
Class clazz = t.getClass();
while (errorPath == null && clazz != null) {
String name = clazz.getName();
errorPath = ctx.getErrorPage(name);
clazz = clazz.getSuperclass();
}
// Bug 3233, ps@psncc.at (Peter Stamfest)
if (errorPath == null ) {
// Use introspection - the error handler is at a lower level,
// doesn't depend on servlet api
Throwable t2=null;
try {
Method m=t.getClass().getMethod( "getRootCause", new Class[] {} );
t2 = (Throwable)m.invoke( t, new Object[] {} );
} catch(Exception ex) {
}
if (t2 != null) {
clazz = t2.getClass();
while (errorPath == null && clazz != null) {
String name = clazz.getName();
errorPath = ctx.getErrorPage(name);
clazz = clazz.getSuperclass();
}
}
if (errorPath != null) t = t2;
}
if( errorPath != null ) {
errorServlet=getHandlerForPath( cm, ctx, errorPath );
String cpath=ctx.getPath();
if( "/".equals( cpath )) cpath="";
// Make sure Jsps will work - needed if the error page is a jsp
if ( null!=errorPath && errorPath.startsWith("/") ) {
req.setAttribute( "javax.servlet.include.request_uri",
cpath + errorPath );
} else {
req.setAttribute( "javax.servlet.include.request_uri",
cpath + "/" + errorPath );
}
req.setAttribute( "javax.servlet.include.servlet_path", errorPath );
}
boolean isDefaultHandler = false;
if ( errorLoop( ctx, req ) ){
log( "Error loop for " + req + " error " + t);
return;
}
if ( errorServlet==null) {
errorServlet = ctx.getServletByName("tomcat.exceptionHandler");
isDefaultHandler = true;
if( debug>0 ) ctx.log( "Using default handler " + errorServlet );
}
if (errorServlet == null) {
ctx.log( "Handler errorServlet is null! errorPath:" + errorPath);
return;
}
// XXX The original code didn't reset the buffer if
// isDefaultHandler : if (!isDefaultHandler && ...
// Is there any reason for that ?
// I also think we should reset the buffer anyway, to get
// in a stable state - even if the buffer is commited
if ( !res.isBufferCommitted())
res.resetBuffer();
req.setAttribute("javax.servlet.error.exception_type", t.getClass());
req.setAttribute("javax.servlet.error.message", t.getMessage());
req.setAttribute("javax.servlet.jsp.jspException", t);
req.setAttribute("tomcat.servlet.error.throwable", t);
req.setAttribute("tomcat.servlet.error.request", req);
if( debug>0 )
ctx.log( "Handler " + errorServlet + " " + errorPath);
// reset error exception
res.setErrorException( null );
Exception ex=null;
try {
errorServlet.service( req, res );
ex=res.getErrorException();
} catch(Exception ex1 ) {
ex=ex1;
}
if( ex!=null && ! (ex instanceof IOException) ) {