List of usage examples for javax.servlet ServletResponse isCommitted
public boolean isCommitted();
From source file:org.nuxeo.ecm.platform.ui.web.auth.oauth2.NuxeoOAuth2Filter.java
protected void process(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String uri = httpRequest.getRequestURI(); if (uri.contains(OAUTH2_SEGMENT)) { String endpoint = uri.split(OAUTH2_SEGMENT)[1]; switch (endpoint) { case ENDPOINT_AUTH: processAuthorization(httpRequest, httpResponse, chain); break; case ENDPOINT_TOKEN: processToken(httpRequest, httpResponse, chain); break; }//from ww w . jav a2s .c o m } else if (isAuthorizedRequest(httpRequest)) { processAuthentication(httpRequest, httpResponse, chain); } if (!response.isCommitted()) { chain.doFilter(request, response); } }
From source file:org.onehippo.forge.hst.pdf.renderer.servlet.HtmlPDFRenderingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(response instanceof HttpServletResponse)) { chain.doFilter(request, response); return;/*w w w .j a va 2s . c o m*/ } if (response.isCommitted()) { log.warn("The servlet response is already committed for the request: '{}'.", ((HttpServletRequest) request).getRequestURI()); chain.doFilter(request, response); return; } ContentCapturingHttpServletResponse capturingResponse = null; InputStream htmlInputStream = null; Reader htmlReader = null; OutputStream pdfOutputStream = null; try { capturingResponse = new ContentCapturingHttpServletResponse((HttpServletResponse) response); chain.doFilter(request, capturingResponse); if (capturingResponse.isWrittenToPrintWriter()) { htmlReader = new CharArrayReader(capturingResponse.toCharArray()); } else { htmlInputStream = new ByteArrayInputStream(capturingResponse.toByteArray()); String characterEncoding = StringUtils.defaultIfBlank(capturingResponse.getCharacterEncoding(), "UTF-8"); htmlReader = new InputStreamReader(htmlInputStream, characterEncoding); } capturingResponse.close(); capturingResponse = null; response.setContentType("application/pdf"); StringBuilder headerValue = new StringBuilder("attachment"); headerValue.append("; filename=\"").append(getDocumentFilename((HttpServletRequest) request)) .append("\""); ((HttpServletResponse) response).addHeader("Content-Disposition", headerValue.toString()); pdfOutputStream = response.getOutputStream(); pdfRenderer.renderHtmlToPDF(htmlReader, true, pdfOutputStream, getDocumentURL((HttpServletRequest) request), getExternalLinkBaseURL((HttpServletRequest) request)); } catch (Exception e) { } finally { if (capturingResponse != null) { capturingResponse.close(); } IOUtils.closeQuietly(pdfOutputStream); IOUtils.closeQuietly(htmlReader); IOUtils.closeQuietly(htmlInputStream); } }
From source file:org.sonar.server.platform.web.RootFilter.java
@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 {/*w w w . ja va2 s . c om*/ doFilter(new ServletRequestWrapper(httpRequest), httpResponse, chain); } catch (Throwable e) { Loggers.get(RootFilter.class).error(format("Processing of request %s failed", toUrl(httpRequest)), e); if (!response.isCommitted()) { httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } } else { // Not an HTTP request, not profiled chain.doFilter(request, response); } }
From source file:web.MockRequestDispatcher.java
@Override public void forward(ServletRequest request, ServletResponse response) { if (response.isCommitted()) { throw new IllegalStateException("Cannot perform forward - response is already committed"); }/* w ww. j a va 2s . co m*/ getMockHttpServletResponse(response).setForwardedUrl(this.url); if (logger.isDebugEnabled()) { logger.debug("MockRequestDispatcher: forwarding to URL [" + this.url + "]"); } }