List of usage examples for javax.servlet.http HttpServletResponse isCommitted
public boolean isCommitted();
From source file:com.silverpeas.peasUtil.GoTo.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { SilverTrace.info("peasUtil", "GoTo.doPost", "root.MSG_GEN_ENTER_METHOD"); String id = getObjectId(req); try {/*from w w w . ja v a 2 s . c o m*/ SilverTrace.info("peasUtil", "GoTo.doPost", "root.MSG_GEN_PARAM_VALUE", "id = " + id); String redirect = getDestination(id, req, res); if (!StringUtil.isDefined(redirect)) { objectNotFound(req, res); } else { if (!res.isCommitted()) { // The response was not previously sent if (redirect == null || !redirect.startsWith("http")) { redirect = URLManager.getApplicationURL() + "/autoRedirect.jsp?" + redirect; } res.sendRedirect(res.encodeRedirectURL(redirect)); } } } catch (AccessForbiddenException afe) { accessForbidden(req, res); } catch (Exception e) { objectNotFound(req, res); } }
From source file:org.springframework.boot.web.servlet.support.ErrorPageFilter.java
private void handleException(HttpServletRequest request, HttpServletResponse response, ErrorWrapperResponse wrapped, Throwable ex) throws IOException, ServletException { Class<?> type = ex.getClass(); String errorPath = getErrorPath(type); if (errorPath == null) { rethrow(ex);/*from w ww.j a v a2 s . c om*/ return; } if (response.isCommitted()) { handleCommittedResponse(request, ex); return; } forwardToErrorPage(errorPath, request, wrapped, ex); }
From source file:org.alfresco.web.app.servlet.ajax.AjaxServlet.java
/** * Handles any error that occurs during the execution of the servlet * /* w w w. j a v a 2 s. c o m*/ * @param response The response * @param cause The cause of the error */ protected void handleError(HttpServletResponse response, RuntimeException cause) throws ServletException, IOException { // if we can send back the 500 error with the error from the top of the // stack as the error status message. // NOTE: if we use the built in support for generating error pages for // 500 errors we can tailor the output for AJAX calls so that the // body of the response can be used to show the error details. if (!response.isCommitted()) { // dump the error if debugging is enabled if (logger.isDebugEnabled()) { logger.error(cause); Throwable theCause = cause.getCause(); if (theCause != null) { logger.error("caused by: ", theCause); } } // extract a message from the exception String msg = cause.getMessage(); if (msg == null) { msg = cause.toString(); } // ALF-9036. We need to trap incomplete sessions if (cause instanceof IllegalStateException) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, cause.getMessage()); } else { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg); } } else { // the response has already been comitted, not much we can do but // let the error through and let the container deal with it throw cause; } }
From source file:org.apache.velocity.tools.view.VelocityViewServlet.java
/** * Manages the {@link ResourceNotFoundException} to send an HTTP 404 result * when needed./*from ww w. j av a2s . com*/ * * @param request The request object. * @param response The response object. * @param e The exception to check. * @throws IOException If something goes wrong when sending the HTTP error. */ protected void manageResourceNotFound(HttpServletRequest request, HttpServletResponse response, ResourceNotFoundException e) throws IOException { String path = ServletUtils.getPath(request); if (getLog().isDebugEnabled()) { getLog().debug("Resource not found for path '" + path + "'", e); } String message = e.getMessage(); if (!response.isCommitted() && path != null && message != null && message.contains("'" + path + "'")) { response.sendError(HttpServletResponse.SC_NOT_FOUND, path); } else { error(request, response, e); throw e; } }
From source file:org.codehaus.groovy.grails.plugins.springsecurity.AjaxAwareAccessDeniedHandler.java
/** * {@inheritDoc}//from ww w . j av a 2 s . c o m * @see org.springframework.security.web.access.AccessDeniedHandler#handle( * javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, * org.springframework.security.access.AccessDeniedException) */ public void handle(final HttpServletRequest request, final HttpServletResponse response, final AccessDeniedException e) throws IOException, ServletException { if (e != null && isLoggedIn() && authenticationTrustResolver.isRememberMe(getAuthentication())) { // user has a cookie but is getting bounced because of IS_AUTHENTICATED_FULLY, // so Acegi won't save the original request request.getSession().setAttribute(WebAttributes.SAVED_REQUEST, new DefaultSavedRequest(request, portResolver)); } if (response.isCommitted()) { return; } boolean ajaxError = ajaxErrorPage != null && SpringSecurityUtils.isAjax(request); if (errorPage == null && !ajaxError) { response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage()); return; } boolean includePort = true; String scheme = request.getScheme(); String serverName = request.getServerName(); int serverPort = portResolver.getServerPort(request); String contextPath = request.getContextPath(); boolean inHttp = "http".equals(scheme.toLowerCase()); boolean inHttps = "https".equals(scheme.toLowerCase()); if (inHttp && (serverPort == 80)) { includePort = false; } else if (inHttps && (serverPort == 443)) { includePort = false; } String redirectUrl = scheme + "://" + serverName + ((includePort) ? (":" + serverPort) : "") + contextPath; if (ajaxError) { redirectUrl += ajaxErrorPage; } else if (errorPage != null) { redirectUrl += errorPage; } response.sendRedirect(response.encodeRedirectURL(redirectUrl)); }
From source file:org.deegree.enterprise.servlet.OGCServletController.java
/** * * * @param request/* ww w . j av a 2 s. c om*/ * @param response * @TODO refactor and optimize code for initializing handler */ public void doService(HttpServletRequest request, HttpServletResponse response) { if (response.isCommitted()) { LOG.logWarning("The response object is already committed!"); } long startTime = System.currentTimeMillis(); address = request.getRequestURL().toString(); String service = null; try { OGCWebServiceRequest ogcRequest = OGCRequestFactory.create(request); LOG.logInfo(StringTools.concat(500, "Handling request '", ogcRequest.getId(), "' from '", request.getRemoteAddr(), "' to service: '", ogcRequest.getServiceName(), "'")); // get service from request service = ogcRequest.getServiceName().toUpperCase(); // get handler instance ServiceDispatcher handler = ServiceLookup.getInstance().getHandler(service, request.getRemoteAddr()); // dispatch request to specific handler handler.perform(ogcRequest, response); } catch (OGCWebServiceException e) { LOG.logError(e.getMessage(), e); sendException(response, e, request, service); } catch (ServiceException e) { if (e.getNestedException() instanceof OGCWebServiceException) { sendException(response, (OGCWebServiceException) e.getNestedException(), request, service); } else { sendException(response, new OGCWebServiceException(this.getClass().getName(), e.getMessage()), request, service); } LOG.logError(e.getMessage(), e); } catch (Exception e) { sendException(response, new OGCWebServiceException(this.getClass().getName(), e.getMessage()), request, service); LOG.logError(e.getMessage(), e); } if (LOG.isDebug()) { LOG.logDebug("OGCServletController: request performed in " + Long.toString(System.currentTimeMillis() - startTime) + " milliseconds."); } }
From source file:org.codehaus.groovy.grails.web.errors.GrailsExceptionResolver.java
protected ModelAndView resolveViewOrForward(Exception ex, UrlMappingsHolder urlMappings, HttpServletRequest request, HttpServletResponse response, ModelAndView mv) { UrlMappingInfo info = matchStatusCode(ex, urlMappings); try {/* ww w. j a va 2 s . c om*/ if (info != null && info.getViewName() != null) { resolveView(request, info, mv); } else if (info != null && info.getControllerName() != null) { String uri = determineUri(request); if (!response.isCommitted()) { if (response instanceof GrailsContentBufferingResponse) { // clear the output from sitemesh before rendering error page ((GrailsContentBufferingResponse) response).deactivateSitemesh(); } forwardRequest(info, request, response, mv, uri); // return an empty ModelAndView since the error handler has been processed return new ModelAndView(); } } return mv; } catch (Exception e) { LOG.error("Unable to render errors view: " + e.getMessage(), e); throw new GrailsRuntimeException(e); } }
From source file:org.jbpm.designer.filter.DesignerBasicAuthSecurityFilter.java
@Override public void doFilter(ServletRequest _request, ServletResponse _response, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) _request; HttpServletResponse response = (HttpServletResponse) _response; HttpSession session = request.getSession(false); User user = this.authenticationService.getUser(); // For HTTP OPTIONS verb/method reply with ACCEPTED status code -- per CORS handshake if (request.getMethod().equals("OPTIONS")) { response.setStatus(HttpServletResponse.SC_ACCEPTED); return;/* ww w . jav a 2 s. co m*/ } try { if (user == null) { if (this.authenticate(request)) { chain.doFilter(request, response); if (response.isCommitted()) { this.authenticationService.logout(); } } else { this.challengeClient(request, response); } } else { chain.doFilter(request, response); } } finally { if (session == null) { session = request.getSession(false); if (session != null) { session.invalidate(); } } } }
From source file:org.orderofthebee.addons.support.tools.share.LogFileHandler.java
protected void handleLogFileRequest(final String filePath, final boolean attach, final HttpServletRequest req, final HttpServletResponse res, final Map<String, Object> model) throws IOException { try {/* w w w . ja va 2 s .c o m*/ final File file = validateFilePath(filePath); final String mimetype = determineMimetypeFromFileName(file); this.contentStreamer.streamContent(req, res, file, file.lastModified(), attach, file.getName(), model, mimetype); } catch (final WebScriptException wsex) { if (!res.isCommitted()) { res.reset(); res.sendError(wsex.getStatus(), wsex.getMessage()); } else { LOGGER.info("Could not send error via committed response", wsex); } } }
From source file:org.nuxeo.ecm.platform.web.common.exceptionhandling.DefaultNuxeoExceptionHandler.java
@Override public boolean handleAnonymousException(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PluggableAuthenticationService authService = (PluggableAuthenticationService) Framework.getRuntime() .getComponent(PluggableAuthenticationService.NAME); if (authService == null) { return false; }/* w ww. j a v a 2 s . c o m*/ authService.invalidateSession(request); String loginURL = getLoginURL(request); if (loginURL == null) { return false; } if (!response.isCommitted()) { request.setAttribute(DISABLE_REDIRECT_REQUEST_KEY, true); response.sendRedirect(loginURL); parameters.getListener().responseComplete(); } else { log.error("Cannot redirect to login page: response is already committed"); } return true; }