List of usage examples for javax.servlet.http HttpServletResponse isCommitted
public boolean isCommitted();
From source file:org.soulwing.cas.filter.AbstractLogoutFilter.java
private void doGlobalLogout(HttpServletResponse response) throws IOException { if (!response.isCommitted()) { SimpleUrlGenerator urlGenerator = new SimpleUrlGenerator(getProtocolConfiguration()); response.sendRedirect(urlGenerator.getLogoutUrl(getRedirectUrl())); } else {/* w ww . ja v a2 s . co m*/ // this really shouldn't happen log.error("skipping CAS global logout because response is committed"); } }
From source file:org.silverpeas.core.web.util.servlet.GoTo.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String id = getObjectId(req); try {//from w ww. java 2s . c o m 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 = URLUtil.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.uberfire.ext.security.server.BasicAuthSecurityFilter.java
@Override public void doFilter(final ServletRequest _request, final ServletResponse _response, final FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) _request; final HttpServletResponse response = (HttpServletResponse) _response; HttpSession session = request.getSession(false); final User user = authenticationService.getUser(); try {/* w w w.j a va2s .co m*/ if (user == null) { if (authenticate(request)) { chain.doFilter(request, response); if (response.isCommitted()) { authenticationService.logout(); } } else { challengeClient(request, response); } } else { chain.doFilter(request, response); } } finally { // invalidate session only when it did not exists before this request // and was created as part of this request if (session == null) { session = request.getSession(false); if (session != null) { session.invalidate(); } } } }
From source file:com.delmar.core.web.filter.ExportDelegate.java
/** * Actually writes exported data. Extracts content from the Map stored in request with the * <code>TableTag.FILTER_CONTENT_OVERRIDE_BODY</code> key. * @param wrapper BufferedResponseWrapper implementation * @param response HttpServletResponse/*from w w w. j av a 2 s . c o m*/ * @param request ServletRequest * @throws java.io.IOException exception thrown by response writer/outputStream */ public static void writeExport(HttpServletResponse response, ServletRequest request, BufferedResponseWrapper wrapper) throws IOException { if (wrapper.isOutRequested()) { // data already written log.debug("Filter operating in unbuffered mode. Everything done, exiting"); return; } // if you reach this point the PARAMETER_EXPORTING has been found, but the special header has never been set in // response (this is the signal from table tag that it is going to write exported data) log.debug("Filter operating in buffered mode. "); Map bean = (Map) request.getAttribute(TableTag.FILTER_CONTENT_OVERRIDE_BODY); if (log.isDebugEnabled()) { log.debug(bean); } Object pageContent = bean.get(TableTagParameters.BEAN_BODY); if (pageContent == null) { if (log.isDebugEnabled()) { log.debug("Filter is enabled but exported content has not been found. Maybe an error occurred?"); } response.setContentType(wrapper.getContentType()); PrintWriter out = response.getWriter(); out.write(wrapper.getContentAsString()); out.flush(); return; } // clear headers if (!response.isCommitted()) { response.reset(); } String filename = (String) bean.get(TableTagParameters.BEAN_FILENAME); String contentType = (String) bean.get(TableTagParameters.BEAN_CONTENTTYPE); if (StringUtils.isNotBlank(filename)) { response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); } String characterEncoding = wrapper.getCharacterEncoding(); String wrappedContentType = wrapper.getContentType(); if (wrappedContentType != null && wrappedContentType.indexOf("charset") > -1) { // charset is already specified (see #921811) characterEncoding = StringUtils.substringAfter(wrappedContentType, "charset="); } if (characterEncoding != null && contentType.indexOf("charset") == -1) //$NON-NLS-1$ { contentType += "; charset=" + characterEncoding; //$NON-NLS-1$ } response.setContentType(contentType); if (pageContent instanceof String) { // text content if (characterEncoding != null) { response.setContentLength(((String) pageContent).getBytes(characterEncoding).length); } else { //FIXME Reliance on default encoding // Found a call to a method which will perform a byte to String (or String to byte) conversion, // and will assume that the default platform encoding is suitable. // This will cause the application behaviour to vary between platforms. // Use an alternative API and specify a charset name or Charset object explicitly. response.setContentLength(((String) pageContent).getBytes().length); } PrintWriter out = response.getWriter(); out.write((String) pageContent); out.flush(); } else { // dealing with binary content byte[] content = (byte[]) pageContent; response.setContentLength(content.length); OutputStream out = response.getOutputStream(); out.write(content); out.flush(); } }
From source file:net.vksn.ecm.spring.tiles3.TilesView.java
@Override protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) throws Exception { exposeModelAsRequestAttributes(model, request); if (this.exposeJstlAttributes) { ServletContext servletContext = getServletContext(); JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext)); }/*w w w. j ava 2 s . c o m*/ if (!response.isCommitted()) { // Tiles is going to use a forward, but some web containers (e.g. // OC4J 10.1.3) // do not properly expose the Servlet 2.4 forward request // attributes... However, // must not do this on Servlet 2.5 or above, mainly for GlassFish // compatibility. if (this.exposeForwardAttributes) { try { WebUtils.exposeForwardRequestAttributes(request); } catch (Exception ex) { // Servlet container rejected to set internal attributes, // e.g. on TriFork. this.exposeForwardAttributes = false; } } } Request tilesRequest = createTilesRequest(request, response); this.renderer.render(getUrl(), tilesRequest); }
From source file:org.soulwing.cas.filter.AbstractLogoutFilter.java
private void doLogoutRedirect(HttpServletResponse response, String url) throws IOException { if (!response.isCommitted()) { response.sendRedirect(url);/*from w w w .j a v a2 s . c om*/ } else { // this really shouldn't happen log.error("skipping logout redirect because response is committed"); } }
From source file:org.esigate.servlet.ProxyFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; IncomingRequest incomingRequest = requestFactory.create(httpServletRequest, httpServletResponse, chain); try {//from w w w. j a v a 2 s . c o m CloseableHttpResponse driverResponse = DriverFactory.proxy(incomingRequest); responseSender.sendResponse(driverResponse, incomingRequest, httpServletResponse); } catch (HttpErrorPage e) { if (!httpServletResponse.isCommitted()) { responseSender.sendResponse(e.getHttpResponse(), incomingRequest, httpServletResponse); } } }
From source file:com.almende.eve.transport.http.DebugServlet.java
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException, ServletException { if (!handleSession(req, resp)) { if (!resp.isCommitted()) { resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); }// w w w.ja v a 2 s.c om resp.flushBuffer(); return; } // retrieve the url and the request body final String body = StringUtil.streamToString(req.getInputStream()); final String url = req.getRequestURI(); final String id = getId(url); if (id == null || id.equals("") || id.equals(myUrl.toASCIIString())) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Couldn't parse URL, missing 'id'"); resp.flushBuffer(); return; } String sender = req.getHeader("X-Eve-SenderUrl"); if (sender == null || sender.equals("")) { sender = "web://" + req.getRemoteUser() + "@" + req.getRemoteAddr(); } URI senderUrl = null; try { senderUrl = new URI(sender); } catch (final URISyntaxException e) { LOG.log(Level.WARNING, "Couldn't parse senderUrl:" + sender, e); } final HttpTransport transport = HttpService.get(myUrl, id); if (transport != null) { try { final String response = transport.receive(body, senderUrl); // TODO: It doesn't need to be json, should we handle mime-types // better? resp.addHeader("Content-Type", "application/json"); resp.getWriter().println(response); resp.getWriter().close(); } catch (final IOException e) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Receiver raised exception:" + e.getMessage()); } } else { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Couldn't load transport"); } resp.flushBuffer(); }
From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java
/** * This method sets the dispatcher type of the given request to DispatcherType.REQUEST. * /*from w w w .j a v a 2 s . c om*/ * ,DispatcherType.REQUEST?. * * @param request * @param response * @throws ServletException * @throws IOException */ public void dispatch(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // jsp/15m8 if (response.isCommitted()) throw new IllegalStateException("dispatch() not allowed after buffer has committed."); // build invocation,if not exist if (_dispatchInvocation == null) { _dispatchInvocation = buildDispatchInvocation(_rawContextURI); } doDispatch(request, response, _dispatchInvocation); }
From source file:org.b3log.latke.servlet.renderer.freemarker.AbstractFreeMarkerRenderer.java
/** * Processes the specified FreeMarker template with the specified request, * data model and response. //from w w w .j a va 2 s . c o m * * <p> * Puts the page response contents into cache with the key getting from * request attribute specified by <i>page cache key</i>. * </p> * * <p> * <b>Note</b>: This method will write page content to the writer of the * specified response without flush/close it. * </p> * * @param html the specified HTML content * @param request the specified request * @param response the specified response * @throws Exception exception */ @SuppressWarnings("unchecked") protected void doRender(final String html, final HttpServletRequest request, final HttpServletResponse response) throws Exception { PrintWriter writer; try { writer = response.getWriter(); } catch (final Exception e) { writer = new PrintWriter(response.getOutputStream()); } if (response.isCommitted()) { // response has been sent redirect writer.flush(); writer.close(); return; } writer.write(html); writer.flush(); writer.close(); }