Refine search
/** * Handle the case where an async request timed out. * <p>The default implementation sends an HTTP 503 error. * @param ex the {@link AsyncRequestTimeoutException }to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2.8 */ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { logger.warn("Async request timed out"); } return new ModelAndView(); }
/** * Called when target not found. By default sends 404 to the response. */ protected void targetNotFound(final ActionRequest actionRequest, final String actionAndResultPath) throws IOException { final HttpServletResponse response = actionRequest.getHttpServletResponse(); if (!response.isCommitted()) { response.sendError(SC_NOT_FOUND, "Result not found: " + actionAndResultPath); } }
/** * Handle the case where an async request timed out. * <p>The default implementation sends an HTTP 503 error. * @param ex the {@link AsyncRequestTimeoutException }to be handled * @param request current HTTP request * @param response current HTTP response * @param handler the executed handler, or {@code null} if none chosen * at the time of the exception (for example, if multipart resolution failed) * @return an empty ModelAndView indicating the exception was handled * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2.8 */ protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { if (!response.isCommitted()) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { logger.warn("Async request timed out"); } return new ModelAndView(); }
if (!response.isCommitted()) { response.addHeader("Guacamole-Status-Code", Integer.toString(guacamoleStatusCode)); response.addHeader("Guacamole-Error-Message", message); response.sendError(guacamoleHttpCode);
private void handleErrorStatus(HttpServletRequest request, HttpServletResponse response, int status, String message) throws ServletException, IOException { if (response.isCommitted()) { handleCommittedResponse(request, null); return; } String errorPath = getErrorPath(this.statuses, status); if (errorPath == null) { response.sendError(status, message); return; } response.setStatus(status); setErrorAttributes(request, status, message); request.getRequestDispatcher(errorPath).forward(request, response); }
private void handleAuthorizationCheckError( String errorMsg, HttpServletRequest servletRequest, HttpServletResponse servletResponse ) { // Send out an alert so there's a centralized collection point for seeing errors of this nature log.makeAlert(errorMsg) .addData("uri", servletRequest.getRequestURI()) .addData("method", servletRequest.getMethod()) .addData("remoteAddr", servletRequest.getRemoteAddr()) .addData("remoteHost", servletRequest.getRemoteHost()) .emit(); if (servletResponse.isCommitted()) { throw new ISE(errorMsg); } else { try { servletResponse.sendError(HttpServletResponse.SC_FORBIDDEN); } catch (Exception e) { throw new RuntimeException(e); } } }
@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { try { if (configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } else { response.sendError(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... LOGGER.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException(LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."), ex); } finally { asyncExt.complete(); } } } finally { requestTimeoutHandler.close(); rethrow(error); } }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request instanceof HttpServletRequest) { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; try { chain.doFilter(new ServletRequestWrapper(httpRequest), httpResponse); } catch (Throwable e) { if (httpResponse.isCommitted()) { // Request has been aborted by the client, nothing can been done as Tomcat has committed the response LOGGER.debug(format("Processing of request %s failed", toUrl(httpRequest)), e); return; } LOGGER.error(format("Processing of request %s failed", toUrl(httpRequest)), e); httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } else { // Not an HTTP request, not profiled chain.doFilter(request, response); } }
@Override public void sendError(int sc, String msg) throws IOException { if (forceAsyncIOWriter || !delegateToNativeResponse) { setStatus(sc, msg); // Prevent StackOverflow boolean b = forceAsyncIOWriter; forceAsyncIOWriter = false; asyncIOWriter.writeError(this, sc, msg); forceAsyncIOWriter = b; } else { if (!_r().isCommitted()) { _r().sendError(sc, msg); } else { logger.warn("Committed error code {} {}", sc, msg); } } }
@Override public void sendError(int sc) throws IOException { if (forceAsyncIOWriter || !delegateToNativeResponse) { setStatus(sc); // Prevent StackOverflow boolean b = forceAsyncIOWriter; forceAsyncIOWriter = false; asyncIOWriter.writeError(this, sc, ""); forceAsyncIOWriter = b; } else { if (!_r().isCommitted()) { _r().sendError(sc); } else { logger.warn("Committed error code {}", sc); } } }
@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { try { if (configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } else { response.sendError(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... LOGGER.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException(LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."), ex); } finally { asyncExt.complete(); } } } finally { requestTimeoutHandler.close(); rethrow(error); } }
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { String targetUrl = determineTargetUrl(request, response); if (response.isCommitted()) { logger.debug("Response has already been committed. Unable to redirect to " + StringUtil.sanitize(targetUrl)); return; } String queryString = request.getQueryString(); if (!StringUtils.isEmpty(queryString)) { targetUrl += "?" + queryString; } request.getSession().invalidate(); try { UrlUtil.validateUrl(targetUrl, request); } catch (IOException e) { logger.error("SECURITY FAILURE Bad redirect location: " + StringUtil.sanitize(targetUrl), e); response.sendError(403); return; } getRedirectStrategy().sendRedirect(request, response, targetUrl); }
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "JSPs only permit GET POST or HEAD"); return; if (out != null && out.getBufferSize() != 0) try { if (response.isCommitted()) { out.flush(); } else {
if (!configSetStatusOverSendError && !response.isCommitted()) { final ContainerResponse responseContext = getResponseContext(); final boolean hasEntity = responseContext.hasEntity(); try { if (reason == null || reason.isEmpty()) { response.sendError(status.getStatusCode()); } else { response.sendError(status.getStatusCode(), reason);
if (!configSetStatusOverSendError && !response.isCommitted()) { final ContainerResponse responseContext = getResponseContext(); final boolean hasEntity = responseContext.hasEntity(); try { if (reason == null || reason.isEmpty()) { response.sendError(status.getStatusCode()); } else { response.sendError(status.getStatusCode(), reason);
if (bufferSize != null && !response.isCommitted()) { try { response.setBufferSize(bufferSize.intValue()); + StringUtil.jQuoteNoXSS(templatePath) + ".", e); response.sendError(HttpServletResponse.SC_NOT_FOUND, "Page template not found"); return;
if (!httpResponse.isCommitted()) { tokenToAuthCookie( httpResponse, } else { httpResponse.sendError(errCode, authenticationEx.getMessage());
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "JSPs only permit GET POST or HEAD"); return; if (out != null && out.getBufferSize() != 0) try { if (response.isCommitted()) { out.flush(); } else {
if(!response.isCommitted()) response.sendError(400, iae.getMessage()); throw iae;
throws IOException { if (response.isCommitted()) { return; response.sendError( metaInfoDataBag._status, metaInfoDataBag._errorMessage);