use of org.apache.catalina.core.ApplicationDispatcher in project Payara by payara.
the class RequestFilterValve method handleError.
private void handleError(Request request, Response response, int statusCode) throws IOException {
ServletRequest sreq = request.getRequest();
ServletResponse sres = response.getResponse();
HttpServletResponse hres = (HttpServletResponse) sres;
ErrorPage errorPage = null;
if (getContainer() instanceof StandardHost) {
errorPage = ((StandardHost) getContainer()).findErrorPage(statusCode);
} else if (getContainer() instanceof StandardContext) {
errorPage = ((StandardContext) getContainer()).findErrorPage(statusCode);
}
if (errorPage != null) {
try {
hres.setStatus(statusCode);
ServletContext servletContext = request.getContext().getServletContext();
ApplicationDispatcher dispatcher = (ApplicationDispatcher) servletContext.getRequestDispatcher(errorPage.getLocation());
if (hres.isCommitted()) {
// Response is committed - including the error page is the
// best we can do
dispatcher.include(sreq, sres);
} else {
// Reset the response (keeping the real error code and message)
response.resetBuffer(true);
dispatcher.dispatch(sreq, sres, DispatcherType.ERROR);
// If we forward, the response is suspended again
response.setSuspended(false);
}
sres.flushBuffer();
} catch (Throwable t) {
if (log.isLoggable(Level.INFO)) {
String msg = MessageFormat.format(rb.getString(LogFacade.CANNOT_PROCESS_ERROR_PAGE_INFO), errorPage.getLocation());
log.log(Level.INFO, msg, t);
}
}
} else {
hres.sendError(statusCode);
}
}
Aggregations