Search in sources :

Example 1 with Dispatcher

use of org.eclipse.jetty.server.Dispatcher in project jetty.project by eclipse.

the class ErrorHandler method doError.

@Override
public void doError(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)) {
        baseRequest.setHandled(true);
        return;
    }
    if (this instanceof ErrorPageMapper) {
        String error_page = ((ErrorPageMapper) this).getErrorPage(request);
        if (error_page != null) {
            String old_error_page = (String) request.getAttribute(ERROR_PAGE);
            ServletContext servlet_context = request.getServletContext();
            if (servlet_context == null)
                servlet_context = ContextHandler.getCurrentContext();
            if (servlet_context == null) {
                LOG.warn("No ServletContext for error page {}", error_page);
            } else if (old_error_page != null && old_error_page.equals(error_page)) {
                LOG.warn("Error page loop {}", error_page);
            } else {
                request.setAttribute(ERROR_PAGE, error_page);
                Dispatcher dispatcher = (Dispatcher) servlet_context.getRequestDispatcher(error_page);
                try {
                    if (LOG.isDebugEnabled())
                        LOG.debug("error page dispatch {}->{}", error_page, dispatcher);
                    if (dispatcher != null) {
                        dispatcher.error(request, response);
                        return;
                    }
                    LOG.warn("No error page found " + error_page);
                } catch (ServletException e) {
                    LOG.warn(Log.EXCEPTION, e);
                    return;
                }
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No Error Page mapping for request({} {}) (using default)", request.getMethod(), request.getRequestURI());
            }
        }
    }
    if (_cacheControl != null)
        response.setHeader(HttpHeader.CACHE_CONTROL.asString(), _cacheControl);
    generateAcceptableResponse(baseRequest, request, response, response.getStatus(), baseRequest.getResponse().getReason());
}
Also used : ServletException(javax.servlet.ServletException) ServletContext(javax.servlet.ServletContext) Dispatcher(org.eclipse.jetty.server.Dispatcher) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 Dispatcher (org.eclipse.jetty.server.Dispatcher)1