Example usage for javax.servlet.http HttpServletResponse isCommitted

List of usage examples for javax.servlet.http HttpServletResponse isCommitted

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse isCommitted.

Prototype

public boolean isCommitted();

Source Link

Document

Returns a boolean indicating if the response has been committed.

Usage

From source file:com.evolveum.midpoint.web.security.MidPointAccessDeniedHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    if (response.isCommitted()) {
        return;/*  ww w. j  a  v  a2 s .c  om*/
    }

    // handle invalid csrf token exception gracefully when user tries to log in/out with expired exception
    if (isLoginLogoutRequest(request) && (accessDeniedException instanceof MissingCsrfTokenException)) {
        response.sendRedirect(request.getContextPath());
        return;
    }

    defaultHandler.handle(request, response, accessDeniedException);
}

From source file:de.itsvs.cwtrpc.controller.UnexpectedErrorFilter.java

protected void processUnexpectedFailure(HttpServletRequest request, HttpServletResponse response, Throwable e) {
    log.error("Unexpected error while processing service request", e);

    if (!response.isCommitted()) {
        response.reset();/*from  w w w . j  a v  a  2s  .  c o  m*/
        /*
         * Since unexpected failure does a non cachable status code, we do
         * not need to initialize caching.
         */
        RPCServletUtils.writeResponseForUnexpectedFailure(getServletContext(), response, e);
    }
}

From source file:uk.ac.cam.caret.sakai.rwiki.tool.command.BasicHttpCommand.java

public void execute(Dispatcher dispatcher, HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    this.beforeDispatch(request, response);
    if (!response.isCommitted()) {
        this.dispatch(dispatcher, request, response);
        this.afterDispatch(request, response);
    }/*from ww  w . ja  v  a  2s .  c  om*/
}

From source file:jeeves.config.springutil.JeevesAccessDeniedHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    if (!response.isCommitted()) {
        if (matcher != null && matcher.matches(request)) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
        }//  w  w  w  .  j a  v  a2s  . co  m
        if (_errorPage != null) {
            request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException);
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            final String referer = _escaper.escape(request.getRequestURI());
            RequestDispatcher dispatcher = request.getRequestDispatcher(_errorPage + "?referer=" + referer);
            dispatcher.forward(request, response);
        } else {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
        }
    }
}

From source file:org.openbravo.authentication.basic.DefaultAuthenticationManager.java

@Override
protected void doLogout(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (!response.isCommitted()) {
        response.sendRedirect(HttpBaseUtils.getLocalAddress(request));
    }/*from w  w w.  j av a  2 s  .c  o m*/
}

From source file:net.sf.ehcache.constructs.web.filter.SimplePageCachingFilterWithBlankPageProblem.java

/**
 * {@inheritDoc}/*from   ww  w  .j a  v a2 s.  c  o m*/
 */
protected void doFilter(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws Exception {
    PageInfo pageInfo = buildPageInfo(request, response, chain);
    if (response.isCommitted()) {
        if (LOG.isWarnEnabled()) {
            LOG.warn("Response cannot be written as it was already committed for " + request.getRequestURL());
        }
    } else {
        writeResponse(request, response, pageInfo);
    }
}

From source file:org.nuxeo.ecm.core.opencmis.bindings.NuxeoCmisAtomPubServlet.java

@Override
protected void printError(Exception ex, HttpServletResponse response) {
    ErrorInfo errorInfo = extractError(ex);
    if (response.isCommitted()) {
        LOG.warn("Failed to send error message to client. " + "Response is already committed.", ex);
        return;/*from   ww w  . ja v  a  2s .c o  m*/
    }

    try {
        response.resetBuffer();
        response.setStatus(errorInfo.statusCode);
        response.setContentType("text/html");
        response.setCharacterEncoding("UTF-8");

        PrintWriter pw = response.getWriter();

        pw.print("<html><head><title>Apache Chemistry OpenCMIS - " + errorInfo.exceptionName + " error</title>"
                + "<style><!--H1 {font-size:24px;line-height:normal;font-weight:bold;background-color:#f0f0f0;color:#003366;border-bottom:1px solid #3c78b5;padding:2px;} "
                + "BODY {font-family:Verdana,arial,sans-serif;color:black;font-size:14px;} "
                + "HR {color:#3c78b5;height:1px;}--></style></head><body>");
        pw.print("<h1>HTTP Status " + errorInfo.statusCode + " - <!--exception-->" + errorInfo.exceptionName
                + "<!--/exception--></h1>");
        pw.print("<p><!--message-->" + StringEscapeUtils.escapeHtml(errorInfo.message) + "<!--/message--></p>");

        String st = ExceptionHelper.getStacktraceAsString(ex);
        if (st != null) {
            pw.print("<hr noshade='noshade'/><!--stacktrace--><pre>\n" + st
                    + "\n</pre><!--/stacktrace--><hr noshade='noshade'/>");
        }

        pw.print("</body></html>");
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        try {
            response.sendError(errorInfo.statusCode, errorInfo.message);
        } catch (Exception en) {
            // there is nothing else we can do
        }
    }
}

From source file:cn.imethan.common.security.handle.AccessDeniedHandlerImpl.java

public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    if (!response.isCommitted()) {
        if (errorPage != null) {
            // Put exception into request scope (perhaps of use to a view)
            request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException);

            // Set the 403 status code.
            response.setStatus(HttpServletResponse.SC_FORBIDDEN);

            // forward to error page.
            RequestDispatcher dispatcher = request.getRequestDispatcher(errorPage);
            dispatcher.forward(request, response);
        } else {//from   ww  w .  ja v a 2s . co  m
            response.sendError(HttpServletResponse.SC_FORBIDDEN, accessDeniedException.getMessage());
        }
    }
}

From source file:org.springframework.security.web.access.AccessDeniedHandlerImpl.java

public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    if (!response.isCommitted()) {
        if (errorPage != null) {
            // Put exception into request scope (perhaps of use to a view)
            request.setAttribute(WebAttributes.ACCESS_DENIED_403, accessDeniedException);

            // Set the 403 status code.
            response.setStatus(HttpStatus.FORBIDDEN.value());

            // forward to error page.
            RequestDispatcher dispatcher = request.getRequestDispatcher(errorPage);
            dispatcher.forward(request, response);
        } else {/*w  w w.  j av a  2 s.co  m*/
            response.sendError(HttpStatus.FORBIDDEN.value(), HttpStatus.FORBIDDEN.getReasonPhrase());
        }
    }
}

From source file:net.ymate.platform.webmvc.view.AbstractView.java

public void render() throws Exception {
    HttpServletResponse _response = WebContext.getResponse();
    if (_response.isCommitted()) {
        return;/*w w  w  . j a va 2 s .  c om*/
    }
    if (StringUtils.isNotBlank(__contentType)) {
        _response.setContentType(__contentType);
    }
    __doRenderView();
}