Search in sources :

Example 1 with ApplicationDispatcher

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);
    }
}
Also used : ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) ApplicationDispatcher(org.apache.catalina.core.ApplicationDispatcher) ErrorPage(org.apache.catalina.deploy.ErrorPage) StandardHost(org.apache.catalina.core.StandardHost) StandardContext(org.apache.catalina.core.StandardContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext)

Aggregations

ServletContext (javax.servlet.ServletContext)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ApplicationDispatcher (org.apache.catalina.core.ApplicationDispatcher)1 StandardContext (org.apache.catalina.core.StandardContext)1 StandardHost (org.apache.catalina.core.StandardHost)1 ErrorPage (org.apache.catalina.deploy.ErrorPage)1