{
request_event = new ServletRequestEvent(getServletContext(),request);
final int s=LazyList.size(request_listeners);
for(int i=0;i<s;i++)
{
final ServletRequestListener listener = (ServletRequestListener)LazyList.get(request_listeners,i);
listener.requestInitialized(request_event);
}
}
// Do the filter/handling thang
if (servlet_holder!=null)
{
base_request.setHandled(true);
if (chain!=null)
chain.doFilter(request, response);
else
servlet_holder.handle(request,response);
}
else
notFound(request, response);
}
catch(RetryRequest e)
{
base_request.setHandled(false);
throw e;
}
catch(EofException e)
{
throw e;
}
catch(Exception e)
{
if (type!=REQUEST)
{
if (e instanceof IOException)
throw (IOException)e;
if (e instanceof RuntimeException)
throw (RuntimeException)e;
if (e instanceof ServletException)
throw (ServletException)e;
}
// unwrap cause
Throwable th=e;
if (th instanceof UnavailableException)
{
Log.debug(th);
}
else if (th instanceof ServletException)
{
Log.debug(th);
Throwable cause=((ServletException)th).getRootCause();
if (cause!=th && cause!=null)
th=cause;
}
// hnndle or log exception
if (th instanceof RetryRequest)
{
base_request.setHandled(false);
throw (RetryRequest)th;
}
else if (th instanceof HttpException)
throw (HttpException)th;
else if (Log.isDebugEnabled())
{
Log.warn(request.getRequestURI(), th);
Log.debug(request.toString());
}
else if (th instanceof IOException || th instanceof UnavailableException)
{
Log.warn(request.getRequestURI()+": "+th);
}
else
{
Log.warn(request.getRequestURI(),th);
}
// TODO httpResponse.getHttpConnection().forceClose();
if (!response.isCommitted())
{
request.setAttribute(ServletHandler.__J_S_ERROR_EXCEPTION_TYPE,th.getClass());
request.setAttribute(ServletHandler.__J_S_ERROR_EXCEPTION,th);
if (th instanceof UnavailableException)
{
UnavailableException ue = (UnavailableException)th;
if (ue.isPermanent())
response.sendError(HttpServletResponse.SC_NOT_FOUND,th.getMessage());
else
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,th.getMessage());
}
else
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,th.getMessage());
}
else
if(Log.isDebugEnabled())Log.debug("Response already committed for handling "+th);
}
catch(Error e)
{
if (type!=REQUEST)
throw e;
Log.warn("Error for "+request.getRequestURI(),e);
if(Log.isDebugEnabled())Log.debug(request.toString());
// TODO httpResponse.getHttpConnection().forceClose();
if (!response.isCommitted())
{
request.setAttribute(ServletHandler.__J_S_ERROR_EXCEPTION_TYPE,e.getClass());
request.setAttribute(ServletHandler.__J_S_ERROR_EXCEPTION,e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,e.getMessage());
}
else
if(Log.isDebugEnabled())Log.debug("Response already committed for handling ",e);
}
finally
{
if (request_listeners!=null)
{
for(int i=LazyList.size(request_listeners);i-->0;)
{
final ServletRequestListener listener = (ServletRequestListener)LazyList.get(request_listeners,i);
listener.requestDestroyed(request_event);
}
}
base_request.setServletName(old_servlet_name);
base_request.setRoleMap(old_role_map);