List of usage examples for javax.servlet.http HttpServletResponse isCommitted
public boolean isCommitted();
From source file:gerenciador.incubadora.controller.ArquivoController.java
@RequestMapping(value = "/imagem/{id}") public ModelAndView download(HttpServletResponse response, @PathVariable Long id) throws FileNotFoundException, Exception { InputStream is = new ByteArrayInputStream( FileUtils.readFileToByteArray(new File(Empreendimento.EMPREENDIMENTO_PATH_LOGO_DEFAULT))); ModelAndView mv = new ModelAndView("redirect:/empreendedor"); Empreendimento empreendimento = ServiceLocator.getEmpreendimentoService().readById(id); mv.addObject("empreendimento", empreendimento); //is.close(); response.setContentType("image/jpeg"); IOUtils.copy(is, response.getOutputStream()); response.flushBuffer();// w ww .j ava2 s .c om if (response.isCommitted()) { System.out.println("Resposta Comitada!"); } return new ModelAndView("empreendimento/new"); }
From source file:org.springframework.boot.actuate.metrics.web.servlet.MetricsFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { StopWatch stopWatch = createStopWatchIfNecessary(request); String path = new UrlPathHelper().getPathWithinApplication(request); int status = HttpStatus.INTERNAL_SERVER_ERROR.value(); try {//from w w w .j ava 2 s.c o m chain.doFilter(request, response); status = getStatus(response); } finally { if (!request.isAsyncStarted()) { if (response.isCommitted()) { status = getStatus(response); } stopWatch.stop(); request.removeAttribute(ATTRIBUTE_STOP_WATCH); recordMetrics(request, path, status, stopWatch.getTotalTimeMillis()); } } }
From source file:com.carolinarollergirls.scoreboard.jetty.XmlScoreBoardServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.doGet(request, response); try {//from ww w . j a v a 2 s . c o m if ("/get".equals(request.getPathInfo())) get(request, response); else if ("/debug".equals(request.getPathInfo())) setDebug(request, response); else if ("/config".equals(request.getPathInfo())) listenerConfig(request, response); else if (request.getPathInfo().endsWith(".xml")) getAll(request, response); else if (!response.isCommitted()) response.sendError(HttpServletResponse.SC_NOT_FOUND); } catch (JDOMException jE) { ScoreBoardManager.printMessage("XmlScoreBoardServlet ERROR: " + jE.getMessage()); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:memedb.httpd.MemeDBHandler.java
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { Request base_request = (request instanceof Request) ? (Request) request : HttpConnection.getCurrentConnection().getRequest(); log.debug("Requested URI: {} target: {}", request.getRequestURI(), target); Credentials cred = getCredentials(request, response); if (cred == null || response.isCommitted()) { base_request.setHandled(true);/*w w w . ja v a 2s. co m*/ return; } // String path = request.getRequestURI().substring(1); String path = target.substring(1); if (path.startsWith(MemeDB.SYS_DB) || path.startsWith(MemeDB.USERS_DB)) { log.warn("Attempted access to {}", path); sendError(response, "not_allowed", "system db", 405); base_request.setHandled(true); return; } if (path.endsWith("/")) { path = path.substring(0, path.length() - 1); } String db = null; String id = null; String rev = null; int slashIndex = path.indexOf("/"); if (slashIndex > -1) { db = path.substring(0, slashIndex); if (slashIndex < path.length()) { id = path.substring(slashIndex + 1); } rev = request.getParameter("rev"); } else { db = path; } if (db.length() == 0) db = null; boolean handled = false; for (BaseRequestHandler handler : baseRequestHandlers) { if (handler.match(cred, request, db, id)) { if (handler instanceof Admin) { Admin a = (Admin) handler; a.setDispatch(dispatch); } handler.handle(cred, request, response, db, id, rev); handled = true; break; } } if (!handled && !allowHtml) { sendError(response, "Could not process request"); handled = true; } if (handled) base_request.setHandled(true); return; }
From source file:org.springframework.boot.context.web.ErrorPageFilter.java
private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { ErrorWrapperResponse wrapped = new ErrorWrapperResponse(response); try {// ww w. j av a2s . co m chain.doFilter(request, wrapped); if (wrapped.hasErrorToSend()) { handleErrorStatus(request, response, wrapped.getStatus(), wrapped.getMessage()); response.flushBuffer(); } else if (!request.isAsyncStarted() && !response.isCommitted()) { response.flushBuffer(); } } catch (Throwable ex) { Throwable exceptionToHandle = ex; if (ex instanceof NestedServletException) { exceptionToHandle = ((NestedServletException) ex).getRootCause(); } handleException(request, response, wrapped, exceptionToHandle); response.flushBuffer(); } }
From source file:org.josso.gateway.filter.ProtocolHandlerFilter.java
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { try {/*from ww w. ja va 2 s. c o m*/ HttpServletRequest hreq = (HttpServletRequest) servletRequest; HttpServletResponse hres = (HttpServletResponse) servletResponse; // Get our security domain SSOContext ctx = Lookup.getInstance().lookupSSOGateway().prepareSSOContext(new SSORequestImpl(hreq)); SecurityDomain sd = ctx.getSecurityDomain(); // TODO : Handle this in a more general way. // See if P3P configuration is enabled // This is required by Microsoft Internet Explorer when embedding JOSSO in a IFRAME SSOWebConfiguration cfg = sd.getSSOWebConfiguration(); if (cfg.isSendP3PHeader()) { if (!hres.isCommitted()) { hres.setHeader("P3P", cfg.getP3PHeaderValue()); if (logger.isDebugEnabled()) logger.debug("Adding P3P Header:" + cfg.getP3PHeaderValue()); } else { logger.warn("Already commited response, cannot set P3P header"); } } // Handle specific protocol requests if (!existJossoSession(hreq, sd)) { SSOProtocolManager pm = sd.getProtocolManager(); // We have a Protocol Manager and the request was processed, do not continue with the chain. if (pm != null && !pm.dispatchRequest(hreq, hres)) return; } } catch (Exception e) { logger.error(e.getMessage(), e); } filterChain.doFilter(servletRequest, servletResponse); }
From source file:org.craftercms.engine.view.CrafterPageView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { request.setAttribute(PAGE_URL_ATTRIBUTE_NAME, page.getStoreUrl()); Map<String, Object> scriptVariables = createScriptVariables(request, response, model); if (CollectionUtils.isNotEmpty(scripts)) { for (Script script : scripts) { executeScript(script, scriptVariables); // If the response has been already committed by one of the scripts, stop and don't render the view if (response.isCommitted()) { logger.debug("Response already committed by script"); return; }/*from w w w . ja va 2 s . c o m*/ } } model.put(KEY_MODEL, page); model.put(KEY_CONTENT_MODEL, page); renderActualView(getPageViewName(), model, request, response); }
From source file:org.nuxeo.ecm.platform.web.common.exceptionhandling.NuxeoSecurityExceptionHandler.java
/** * Handles the Security Error when the user is anonymous. * * @return {@code true} if the Security Error is handled so that the calling * method won't fallback on the default handler, {@code false} * otherwise./*from w w w . j a va 2 s.c o m*/ */ protected boolean handleAnonymousException(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { getAuthenticationService().invalidateSession(request); Map<String, String> urlParameters = new HashMap<String, String>(); urlParameters.put(SECURITY_ERROR, "true"); urlParameters.put(FORCE_ANONYMOUS_LOGIN, "true"); if (request.getAttribute(REQUESTED_URL) != null) { urlParameters.put(REQUESTED_URL, (String) request.getAttribute(REQUESTED_URL)); } else { urlParameters.put(REQUESTED_URL, NuxeoAuthenticationFilter.getRequestedUrl(request)); } // Redirect to login with urlParameters if (!response.isCommitted()) { String baseURL = getAuthenticationService().getBaseURL(request) + LOGOUT_PAGE; request.setAttribute(DISABLE_REDIRECT_REQUEST_KEY, true); baseURL = URIUtils.addParametersToURIQuery(baseURL, urlParameters); response.sendRedirect(baseURL); FacesContext fContext = FacesContext.getCurrentInstance(); if (fContext != null) { fContext.responseComplete(); } else { log.error("Cannot set response complete: faces context is null"); } } else { log.error("Cannot redirect to login page: response is already committed"); } return true; }
From source file:org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer.java
@Override public void render(final HTTPRequestContext context) { final HttpServletResponse response = context.getResponse(); response.setContentType("text/html"); response.setCharacterEncoding("UTF-8"); PrintWriter writer;//from www . ja v a 2 s . c o m try { writer = response.getWriter(); } catch (final Exception e) { try { writer = new PrintWriter(response.getOutputStream()); } catch (final IOException ex) { LOGGER.log(Level.SEVERE, "Can not get response writer", ex); return; } } if (response.isCommitted()) { // response has been sent redirect writer.flush(); writer.close(); return; } try { final HttpServletRequest request = context.getRequest(); final Template template = getTemplate((String) request.getAttribute(Keys.TEMAPLTE_DIR_NAME), templateName); if (Templates.hasExpression(template, "${request}")) { dataModel.put(Keys.REQUEST, request); } beforeRender(context); final String html = genHTML(context.getRequest(), dataModel, template); doRender(html, context.getRequest(), response); afterRender(context); } catch (final Exception e) { LOGGER.log(Level.SEVERE, "FreeMarker renders error", e); try { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (final IOException ex) { LOGGER.log(Level.SEVERE, "Can not send error 500!", ex); } } }