public void reset() throws IllegalStateException { resp.reset(); }
public ServletStream reset() { response.reset(); return this; } }
@Override public void reset() { response.reset(); }
/** * * @see javax.servlet.ServletResponse#reset() */ @Override public void reset() { response.reset(); }
@Override public void reset() { rsp.reset(); }
public void reset() { response.reset(); }
@Override protected void preResponseCommit() { long lastModified = lastModifiedData.getLastModified(); long ifModifiedSince = request.getDateHeader("If-Modified-Since"); if (lastModified > -1 && !response.containsHeader("Last-Modified")) { if (ifModifiedSince < (lastModified / 1000 * 1000)) { response.setDateHeader("Last-Modified", lastModified); } else { response.reset(); response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); } } } }
protected void setDownloadResponse(String downloadFile, final HttpServletResponse response) { File file = new File(downloadFile); try (InputStream fileInputStream = new FileInputStream(file); OutputStream output = response.getOutputStream()) { response.reset(); response.setContentType("application/octet-stream"); response.setContentLength((int) (file.length())); response.setHeader("Content-Disposition", "attachment; filename=\"" + file.getName() + "\""); IOUtils.copyLarge(fileInputStream, output); output.flush(); } catch (IOException e) { throw new InternalErrorException("Failed to download file: " + e.getMessage(), e); } }
private void setResponseForInvalidUri(final HttpServletResponse response, final Throwable throwable) throws IOException { LOGGER.log(Level.FINER, "Error while processing request.", throwable); final Response.Status badRequest = Response.Status.BAD_REQUEST; if (webComponent.configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(badRequest.getStatusCode(), badRequest.getReasonPhrase()); } else { response.sendError(badRequest.getStatusCode(), badRequest.getReasonPhrase()); } }
private void setResponseForInvalidUri(final HttpServletResponse response, final Throwable throwable) throws IOException { LOGGER.log(Level.FINER, "Error while processing request.", throwable); final Response.Status badRequest = Response.Status.BAD_REQUEST; if (webComponent.configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(badRequest.getStatusCode(), badRequest.getReasonPhrase()); } else { response.sendError(badRequest.getStatusCode(), badRequest.getReasonPhrase()); } }
public void download() throws IOException { // Prepare. byte[] pdfData = getItSomehow(); FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); // Initialize response. response.reset(); // Some JSF component library or some Filter might have set some headers in the buffer beforehand. We want to get rid of them, else it may collide. response.setContentType("application/pdf"); // Check http://www.iana.org/assignments/media-types for all types. Use if necessary ServletContext#getMimeType() for auto-detection based on filename. response.setHeader("Content-disposition", "attachment; filename=\"name.pdf\""); // The Save As popup magic is done here. You can give it any filename you want, this only won't work in MSIE, it will use current request URL as filename instead. // Write file to response. OutputStream output = response.getOutputStream(); output.write(pdfData); output.close(); // Inform JSF to not take the response in hands. facesContext.responseComplete(); // Important! Else JSF will attempt to render the response which obviously will fail since it's already written with a file and closed. }
private void forwardToErrorPage(String path, HttpServletRequest request, HttpServletResponse response, Throwable ex) throws ServletException, IOException { if (logger.isErrorEnabled()) { String message = "Forwarding to error page from request " + getDescription(request) + " due to exception [" + ex.getMessage() + "]"; logger.error(message, ex); } setErrorAttributes(request, 500, ex.getMessage()); request.setAttribute(ERROR_EXCEPTION, ex); request.setAttribute(ERROR_EXCEPTION_TYPE, ex.getClass()); response.reset(); response.setStatus(500); request.getRequestDispatcher(path).forward(request, response); request.removeAttribute(ERROR_EXCEPTION); request.removeAttribute(ERROR_EXCEPTION_TYPE); }
public void download() throws IOException { FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); HttpServletResponse response = (HttpServletResponse) externalContext.getResponse(); response.reset(); // Some JSF component library or some Filter might have set some headers in the buffer beforehand. We want to get rid of them, else it may collide. response.setContentType("application/xml"); // Check http://www.iana.org/assignments/media-types for all types. Use if necessary ServletContext#getMimeType() for auto-detection based on filename. response.setHeader("Content-disposition", "attachment; filename=\"name.xml\""); // The Save As popup magic is done here. You can give it any filename you want, this only won't work in MSIE, it will use current request URL as filename instead. BufferedInputStream input = null; BufferedOutputStream output = null; try { input = new BufferedInputStream(getYourXmlAsInputStream()); output = new BufferedOutputStream(response.getOutputStream()); byte[] buffer = new byte[10240]; for (int length; (length = input.read(buffer)) > 0;) { output.write(buffer, 0, length); } } finally { close(output); close(input); } facesContext.responseComplete(); // Important! Else JSF will attempt to render the response which obviously will fail since it's already written with a file and closed. }
@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 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); } }
@Test void testPreResponseCommit() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(true); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse, never()).setDateHeader("Last-Modified", 1); verify(originalResponse, never()).reset(); verify(originalResponse).containsHeader("Last-Modified"); }
@Test void testPreResponseCommit5() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(false); when(originalRequest.getDateHeader("If-Modified-Since")).thenReturn(Long.MAX_VALUE); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse).reset(); }
@Test void testPreResponseCommit3() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(-1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(false); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse, never()).setDateHeader("Last-Modified", 1); verify(originalResponse, never()).reset(); verify(lastModifiedData).getLastModified(); }
@Test void testPreResponseCommit2() { // setup decoraResponseWrapper = new DecoraResponseWrapper(originalRequest, originalResponse, lastModifiedData, decoraManager); when(lastModifiedData.getLastModified()).thenReturn(Long.valueOf(-1)); when(originalResponse.containsHeader("Last-Modified")).thenReturn(true); // when decoraResponseWrapper.preResponseCommit(); // then verify(originalResponse, never()).setDateHeader("Last-Modified", 1); verify(originalResponse, never()).reset(); verify(lastModifiedData).getLastModified(); }
@Test public void test_reset() { underTest.stream().reset(); verify(response).reset(); }