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:br.com.sicva.seguranca.DirecionadorUsuario.java

protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException {

    String targetUrl = determineTargetUrl(authentication);

    if (response.isCommitted()) {
        logger.debug("Response has already been committed. Unable to redirect to " + targetUrl);
        return;//from  ww  w .j  a v  a 2s .  c  om
    }

    redirectStrategy.sendRedirect(request, response, targetUrl);
}

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

@Override
public void printError(CallContext context, Exception ex, HttpServletRequest request,
        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 w  w  w  . j av  a  2 s  .c o  m
    }

    String token = (context instanceof BrowserCallContextImpl ? ((BrowserCallContextImpl) context).getToken()
            : null);

    if (token == null) {
        response.resetBuffer();
        CALL.setStatus(request, response, errorInfo.statusCode);

        String message = ex.getMessage();
        if (!(ex instanceof CmisBaseException)) {
            message = "An error occurred!";
        }

        JSONObject jsonResponse = new JSONObject();
        jsonResponse.put(ERROR_EXCEPTION, errorInfo.exceptionName);
        jsonResponse.put(ERROR_MESSAGE, errorInfo.message);

        String st = ExceptionHelper.getStacktraceAsString(ex);
        if (st != null) {
            jsonResponse.put(ERROR_STACKTRACE, st);
        }

        try {
            CALL.writeJSON(jsonResponse, request, response);
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            try {
                response.sendError(errorInfo.statusCode, message);
            } catch (Exception en) {
                // there is nothing else we can do
            }
        }
    } else {
        CALL.setStatus(request, response, SC_OK);
        response.setContentType(AbstractBrowserServiceCall.HTML_MIME_TYPE);
        response.setContentLength(0);

        if (context != null) {
            CALL.setCookie(request, response, context.getRepositoryId(), token, CALL
                    .createCookieValue(errorInfo.statusCode, null, errorInfo.exceptionName, ex.getMessage()));
        }
    }
}

From source file:com.haulmont.cuba.restapi.RestFileDownloadController.java

private void error(HttpServletResponse response) throws IOException {
    if (!response.isCommitted())
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
}

From source file:de.steilerdev.myVerein.server.security.rest.RestAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException {
    logger.warn("[{}] Unauthorized access to authentication entry point",
            SecurityHelper.getClientIpAddr(request));
    if (!response.isCommitted()) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
    }//  ww  w . j  a  va2  s. c o m
}

From source file:de.steilerdev.myVerein.server.security.rest.RestAuthenticationFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    logger.warn("[{}] Authentication failed: {}", SecurityHelper.getClientIpAddr(request),
            exception.getMessage());//from  w ww.  j  a v a2s .  com
    if (!response.isCommitted()) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
                "Authentication failed: " + exception.getMessage());
    }
}

From source file:org.parancoe.plugins.security.SecureInterceptor.java

/**
 * Delegates request to filter chain./*w  ww . ja  v a2s .  c o  m*/
 */
@Override
public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object handler) throws Exception {
    delegate.doFilter(req, res, new ParancoeFilterChain());
    populateMDC();
    req.getSession(false);
    if (res.isCommitted()) {
        logger.debug("Response is committed!");
        return false;
    }
    return true;

}

From source file:edu.cornell.mannlib.vitro.webapp.filters.JSessionStripFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse hResponse = (HttpServletResponse) response;
    HttpServletRequest hRequest = (HttpServletRequest) request;
    hRequest.setAttribute(USING_JSESSION_STRIP, "true");

    if (hResponse.isCommitted()) {
        log.error("response is comitted cannot forward "
                + " (check you haven't done anything to the response (ie, written to it) before here)");
        return;/* w w w .j  ava2s  . c  om*/
    }
    chain.doFilter(hRequest, new StripSessionIdWrapper(hResponse));

}

From source file:org.apache.abdera.protocol.server.servlet.AbderaServlet.java

private void error(String message, Throwable t, HttpServletResponse response) throws IOException {
    if (t != null)
        log.error(message, t);//from  www .  j  a va2  s.co m
    else
        log.error(message);

    if (response.isCommitted()) {
        log.error("Could not write an error message as the headers & HTTP status were already committed!");
    } else {
        response.setStatus(500);
        StreamWriter sw = getAbdera().newStreamWriter().setOutputStream(response.getOutputStream(), "UTF-8");
        Error.create(sw, 500, message, t);
        sw.close();
    }
}

From source file:com.beto.test.securityinterceptor.security.MySimpleUrlAuthenticationSuccessHandler.java

protected void handle(HttpServletRequest request, HttpServletResponse response, Authentication authentication)
        throws IOException {
    LOGGER.debug("handle method is called...");
    String targetUrl = determineTargetUrl(authentication);

    if (response.isCommitted()) {
        LOGGER.debug("Response has already been committed. Unable to redirect to " + targetUrl);
        return;/*from  w w w. j av  a 2 s  .c  o m*/
    }

    redirectStrategy.sendRedirect(request, response, targetUrl);
}

From source file:com.alfaariss.oa.helper.stylesheet.handler.RedirectHandler.java

/**
 * @see com.alfaariss.oa.helper.stylesheet.handler.AbstractStyleSheetHandler#process(com.alfaariss.oa.api.session.ISession, javax.servlet.http.HttpServletResponse, boolean)
 *///from   w ww.  j  av a  2 s. c o m
public void process(ISession session, HttpServletResponse response, boolean isWireless)
        throws StyleSheetException {
    try {
        String sStyleSheet = super.resolveStyleSheetLocation(session, isWireless);
        if (sStyleSheet != null) {
            if (response.isCommitted()) {
                _logger.error("Response already committed");
                throw new StyleSheetException(SystemErrors.ERROR_RESOURCE_CONNECT);
            }

            response.sendRedirect(sStyleSheet);
        }
    } catch (StyleSheetException e) {
        throw e;
    } catch (Exception e) {
        _logger.fatal("Unable to process request", e);
        throw new StyleSheetException(SystemErrors.ERROR_INTERNAL);
    }
}