List of usage examples for javax.servlet.http HttpServletResponse resetBuffer
public void resetBuffer();
From source file:org.apache.openmeetings.servlet.outputhandler.BackupExport.java
public void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, ServletContext servletCtx) throws ServletException, IOException { String sid = httpServletRequest.getParameter("sid"); if (sid == null) { sid = "default"; }//from w w w . ja va 2 s .com log.debug("sid: " + sid); Long users_id = sessiondataDao.checkSession(sid); Long user_level = userManager.getUserLevelByID(users_id); log.debug("users_id: " + users_id); log.debug("user_level: " + user_level); if (authLevelUtil.checkAdminLevel(user_level)) { // if (true) { String includeFileOption = httpServletRequest.getParameter("includeFileOption"); boolean includeFiles = includeFileOption == null || "yes".equals(includeFileOption); String moduleName = httpServletRequest.getParameter("moduleName"); if (moduleName == null) { moduleName = "moduleName"; } log.debug("moduleName: " + moduleName); if (moduleName.equals("backup")) { /* * ##################### Create Base Folder structure */ File working_dir = OmFileHelper.getUploadBackupDir(); String dateString = "backup_" + CalendarPatterns.getTimeForStreamId(new Date()); File backup_dir = new File(working_dir, dateString); String requestedFile = dateString + ".zip"; File backupFile = new File(backup_dir, requestedFile); try { performExport(backupFile, backup_dir, includeFiles); httpServletResponse.reset(); httpServletResponse.resetBuffer(); httpServletResponse.setContentType("APPLICATION/OCTET-STREAM"); httpServletResponse.setHeader("Content-Disposition", "attachment; filename=\"" + requestedFile + "\""); httpServletResponse.setHeader("Content-Length", "" + backupFile.length()); OutputStream out = httpServletResponse.getOutputStream(); OmFileHelper.copyFile(backupFile, out); out.flush(); out.close(); } catch (Exception er) { log.error("Error exporting: ", er); } if (backupFile.exists()) { // log.debug("DELETE :1: "+backupFile.getCanonicalPath()); backupFile.delete(); } FileHelper.removeRec(backup_dir); } } else { log.debug("ERROR LangExport: not authorized FileDownload " + (new Date())); } }
From source file:org.apache.openmeetings.servlet.outputhandler.DownloadHandler.java
@Override protected void service(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException { try {/* w ww. j a va 2s. c om*/ httpServletRequest.setCharacterEncoding("UTF-8"); log.debug("\nquery = " + httpServletRequest.getQueryString()); log.debug("\n\nfileName = " + httpServletRequest.getParameter("fileName")); log.debug("\n\nparentPath = " + httpServletRequest.getParameter("parentPath")); String queryString = httpServletRequest.getQueryString(); if (queryString == null) { queryString = ""; } String sid = httpServletRequest.getParameter("sid"); if (sid == null) { sid = "default"; } log.debug("sid: " + sid); Long users_id = getBean(SessiondataDao.class).checkSession(sid); Long user_level = getBean(UserManager.class).getUserLevelByID(users_id); if (user_level != null && user_level > 0) { String room_id = httpServletRequest.getParameter("room_id"); if (room_id == null) { room_id = "default"; } String moduleName = httpServletRequest.getParameter("moduleName"); if (moduleName == null) { moduleName = "nomodule"; } String parentPath = httpServletRequest.getParameter("parentPath"); if (parentPath == null) { parentPath = "nomodule"; } String requestedFile = httpServletRequest.getParameter("fileName"); if (requestedFile == null) { requestedFile = ""; } String fileExplorerItemIdParam = httpServletRequest.getParameter("fileExplorerItemId"); Long fileExplorerItemId = null; if (fileExplorerItemIdParam != null) { fileExplorerItemId = Long.parseLong(fileExplorerItemIdParam); } // make a complete name out of domain(organisation) + roomname String roomName = room_id; // trim whitespaces cause it is a directory name roomName = StringUtils.deleteWhitespace(roomName); // Get the current User-Directory File working_dir; // Add the Folder for the Room if (moduleName.equals("lzRecorderApp")) { working_dir = OmFileHelper.getStreamsHibernateDir(); } else if (moduleName.equals("videoconf1")) { working_dir = OmFileHelper.getUploadRoomDir(roomName); if (parentPath.length() != 0 && !parentPath.equals("/")) { working_dir = new File(working_dir, parentPath); } } else if (moduleName.equals("userprofile")) { working_dir = OmFileHelper.getUploadProfilesUserDir(users_id); logNonExistentFolder(working_dir); } else if (moduleName.equals("remoteuserprofile")) { String remoteUser_id = httpServletRequest.getParameter("remoteUserid"); working_dir = OmFileHelper .getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id); logNonExistentFolder(working_dir); } else if (moduleName.equals("remoteuserprofilebig")) { String remoteUser_id = httpServletRequest.getParameter("remoteUserid"); working_dir = OmFileHelper .getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id); logNonExistentFolder(working_dir); requestedFile = getBigProfileUserName(working_dir); } else if (moduleName.equals("chat")) { String remoteUser_id = httpServletRequest.getParameter("remoteUserid"); working_dir = OmFileHelper .getUploadProfilesUserDir(remoteUser_id == null ? "0" : remoteUser_id); logNonExistentFolder(working_dir); requestedFile = getChatUserName(working_dir); } else { working_dir = OmFileHelper.getUploadRoomDir(roomName); } if (!moduleName.equals("nomodule")) { log.debug("requestedFile: " + requestedFile + " current_dir: " + working_dir); File full_path = new File(working_dir, requestedFile); // If the File does not exist or is not readable show/load a // place-holder picture if (!full_path.exists() || !full_path.canRead()) { if (!full_path.canRead()) { log.debug("LOG DownloadHandler: The request file is not readable "); } else { log.debug( "LOG DownloadHandler: The request file does not exist / has already been deleted"); } log.debug("LOG ERROR requestedFile: " + requestedFile); // replace the path with the default picture/document if (requestedFile.endsWith(".jpg")) { log.debug("LOG endsWith d.jpg"); log.debug("LOG moduleName: " + moduleName); requestedFile = DownloadHandler.defaultImageName; if (moduleName.equals("remoteuserprofile")) { requestedFile = DownloadHandler.defaultProfileImageName; } else if (moduleName.equals("remoteuserprofilebig")) { requestedFile = DownloadHandler.defaultProfileImageNameBig; } else if (moduleName.equals("userprofile")) { requestedFile = DownloadHandler.defaultProfileImageName; } else if (moduleName.equals("chat")) { requestedFile = DownloadHandler.defaultChatImageName; } } else if (requestedFile.endsWith(".swf")) { requestedFile = DownloadHandler.defaultSWFName; } else { requestedFile = DownloadHandler.defaultImageName; } full_path = new File(OmFileHelper.getDefaultDir(), requestedFile); } log.debug("full_path: " + full_path); if (!full_path.exists() || !full_path.canRead()) { if (!full_path.canRead()) { log.debug( "DownloadHandler: The request DEFAULT-file does not exist / has already been deleted"); } else { log.debug( "DownloadHandler: The request DEFAULT-file does not exist / has already been deleted"); } // no file to handle abort processing return; } // Requested file is outside OM webapp folder File curDirFile = OmFileHelper.getOmHome(); if (!full_path.getCanonicalPath().startsWith(curDirFile.getCanonicalPath())) { throw new Exception("Invalid file requested: f2.cp == " + full_path.getCanonicalPath() + "; curDir.cp == " + curDirFile.getCanonicalPath()); } // Default type - Explorer, Chrome and others int browserType = 0; // Firefox and Opera browsers if (httpServletRequest.getHeader("User-Agent") != null) { if ((httpServletRequest.getHeader("User-Agent").contains("Firefox")) || (httpServletRequest.getHeader("User-Agent").contains("Opera"))) { browserType = 1; } } log.debug("Detected browser type:" + browserType); httpServletResponse.reset(); httpServletResponse.resetBuffer(); OutputStream out = httpServletResponse.getOutputStream(); if (requestedFile.endsWith(".swf")) { // trigger download to SWF => THIS is a workaround for // Flash Player 10, FP 10 does not seem // to accept SWF-Downloads with the Content-Disposition // in the Header httpServletResponse.setContentType("application/x-shockwave-flash"); httpServletResponse.setHeader("Content-Length", "" + full_path.length()); } else { httpServletResponse.setContentType("APPLICATION/OCTET-STREAM"); String fileNameResult = requestedFile; if (fileExplorerItemId != null && fileExplorerItemId > 0) { FileExplorerItem fileExplorerItem = getBean(FileExplorerItemDao.class) .getFileExplorerItemsById(fileExplorerItemId); if (fileExplorerItem != null) { fileNameResult = fileExplorerItem.getFileName().substring(0, fileExplorerItem.getFileName().length() - 4) + fileNameResult.substring(fileNameResult.length() - 4, fileNameResult.length()); } } if (browserType == 0) { httpServletResponse.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(fileNameResult, "UTF-8")); } else { httpServletResponse.setHeader("Content-Disposition", "attachment; filename*=UTF-8'en'" + java.net.URLEncoder.encode(fileNameResult, "UTF-8")); } httpServletResponse.setHeader("Content-Length", "" + full_path.length()); } OmFileHelper.copyFile(full_path, out); out.flush(); out.close(); } } else { log.error("ERROR DownloadHandler: not authorized FileDownload "); } } catch (ServerNotInitializedException e) { return; } catch (Exception er) { log.error("Error downloading: ", er); } }
From source file:org.apache.sling.auth.core.impl.HttpBasicAuthenticationHandler.java
/** * Sends status <code>401</code> (Unauthorized) with a * <code>WWW-Authenticate</code> requesting standard HTTP header * authentication with the <code>Basic</code> scheme and the configured * realm name.// www . ja v a 2 s .c om * * @param response The response object to which to send the request * @return <code>true</code> if the 401/UNAUTHORIZED method has successfully * been sent and the response has been committed. */ boolean sendUnauthorized(HttpServletResponse response) { if (response.isCommitted()) { log.error("sendUnauthorized: Cannot send 401/UNAUTHORIZED; response is already committed"); } else { response.resetBuffer(); /* * TODO: Check whether we have to redirect * If this is a GET request not targeted at the registration path * for which this handler is selected we have to redirect to the * registration path using either the provided resource attribute * or parameter or the current URL as the "resource" parameter * for the redirect and also setting the "sling:authRequestLogin" * parameter to "BASIC" to get the 401 response for the registration * path and redirect back to actual path afterwards. */ // just set the status because this may be called as part of an // error handler in which case sendError would result in an error // handler loop and thus be ignored. response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setHeader(HEADER_WWW_AUTHENTICATE, AUTHENTICATION_SCHEME_BASIC + " realm=\"" + this.realm + "\""); try { response.flushBuffer(); return true; } catch (IOException ioe) { log.error("sendUnauthorized: Failed requesting authentication", ioe); } } return false; }
From source file:org.apache.sling.auth.form.impl.FormAuthenticationHandler.java
/** * Called after successful login with the given authentication info. This * implementation ensures the authentication data is set in either the * cookie or the HTTP session with the correct security tokens. * <p>//from w w w . j a va 2 s . co m * If no authentication data already exists, it is created. Otherwise if the * data has expired the data is updated with a new security token and a new * expiry time. * <p> * If creating or updating the authentication data fails, it is actually * removed from the cookie or the HTTP session and future requests will not * be authenticated any longer. */ @Override public boolean authenticationSucceeded(HttpServletRequest request, HttpServletResponse response, AuthenticationInfo authInfo) { /* * Note: This method is called if this handler provided credentials * which succeeded login into the repository */ // ensure fresh authentication data refreshAuthData(request, response, authInfo); final boolean result; // SLING-1847: only consider a resource redirect if this is a POST request // to the j_security_check URL if (REQUEST_METHOD.equals(request.getMethod()) && request.getRequestURI().endsWith(REQUEST_URL_SUFFIX)) { if (DefaultAuthenticationFeedbackHandler.handleRedirect(request, response)) { // terminate request, all done in the default handler result = false; } else { // check whether redirect is requested by the resource parameter final String targetResource = AuthUtil.getLoginResource(request, null); if (targetResource != null) { try { if (response.isCommitted()) { throw new IllegalStateException("Response is already committed"); } response.resetBuffer(); StringBuilder b = new StringBuilder(); if (AuthUtil.isRedirectValid(request, targetResource)) { b.append(targetResource); } else if (request.getContextPath().length() == 0) { b.append("/"); } else { b.append(request.getContextPath()); } response.sendRedirect(b.toString()); } catch (IOException ioe) { log.error("Failed to send redirect to: " + targetResource, ioe); } // terminate request, all done result = true; } else { // no redirect, hence continue processing result = false; } } } else { // no redirect, hence continue processing result = false; } // no redirect return result; }
From source file:org.deegree.services.authentication.HttpBasicAuthentication.java
/** * Handles the authentication./* www.ja v a2 s . c om*/ * * @param response * @param e * @throws IOException */ private void doAuthenticationException(HttpServletResponse response, SecurityException e) throws IOException { LOG.debug("SecurityException: "); response.reset(); response.resetBuffer(); response.setHeader("WWW-Authenticate", "Basic realm=\" Backroom "); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.flushBuffer(); }
From source file:org.entando.entando.plugins.jpoauthclient.aps.system.services.client.ProviderConnectionManager.java
/** * Handle an exception that occurred while processing an HTTP request. * Depending on the exception, either send a response, redirect the client * or propagate an exception.// w w w . j av a 2s . c o m */ public void handleException(ApiMethodRequestBean bean, Exception e, HttpServletRequest request, HttpServletResponse response, OAuthConsumer consumer, boolean redirectOAuthErrorPage) throws IOException, ServletException { if (e instanceof RedirectException) { RedirectException redirect = (RedirectException) e; String targetURL = redirect.getTargetURL(); if (targetURL != null) { response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", targetURL); } } else if (e instanceof OAuthProblemException) { OAuthProblemException p = (OAuthProblemException) e; String problem = p.getProblem(); List<String> recoverableProblems = Arrays.asList(RECOVERABLE_PROBLEMS); if (consumer != null && recoverableProblems.contains(problem)) { try { CookieMap cookies = new CookieMap(request, response); OAuthAccessor accessor = this.newAccessor(consumer, cookies); this.getAccessToken(bean, request, cookies, accessor); } catch (Exception e2) { handleException(bean, e2, request, response, null, redirectOAuthErrorPage); } } else if (redirectOAuthErrorPage) { try { StringWriter s = new StringWriter(); PrintWriter pw = new PrintWriter(s); e.printStackTrace(pw); pw.flush(); p.setParameter("stack trace", s.toString()); } catch (Exception rats) { //nothing to catch } response.setStatus(p.getHttpStatusCode()); response.resetBuffer(); request.setAttribute("OAuthProblemException", p); request.getRequestDispatcher("/WEB-INF/plugins/jpoauthclient/OAuthProblemException.jsp") .forward(request, response); } } else if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof ServletException) { throw (ServletException) e; } else if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ServletException(e); } }
From source file:org.ireland.jnetty.webapp.ErrorPageManager.java
public void sendServletErrorImpl(Throwable e, ServletRequest req, ServletResponse res) throws IOException { HttpServletResponse response = (HttpServletResponse) res; HttpServletRequest request = (HttpServletRequest) req; Throwable rootExn = e;//from w w w. j a v a 2 s. com Throwable errorPageExn = null; LineMap lineMap = null; try { response.reset(); } catch (IllegalStateException e1) { } if (req.isAsyncStarted()) { AsyncContext async = req.getAsyncContext(); if (async != null) async.complete(); } if (response instanceof HttpServletResponseImpl) { HttpServletResponseImpl resFacade = (HttpServletResponseImpl) response; resFacade.killCache(); resFacade.setNoCache(true); } if (rootExn instanceof ClientDisconnectException) throw (ClientDisconnectException) rootExn; String location = null; String title = "500 Servlet Exception"; boolean isBadRequest = false; boolean doStackTrace = true; boolean isCompileException = false; boolean isServletException = false; Throwable compileException = null; String lineMessage = null; boolean lookupErrorPage = true; while (true) { if (rootExn instanceof LineMapException) lineMap = ((LineMapException) rootExn).getLineMap(); if (lookupErrorPage) { errorPageExn = rootExn; } if (rootExn instanceof DisplayableException) { doStackTrace = false; isCompileException = true; if (compileException == null) compileException = rootExn; } else if (rootExn instanceof CompileException) { doStackTrace = false; isCompileException = true; if (compileException == null) // ! isLineCompileException) compileException = rootExn; } else if (rootExn instanceof LineException) { if (lineMessage == null) lineMessage = rootExn.getMessage(); } if (rootExn instanceof BadRequestException) { isBadRequest = true; } if (rootExn instanceof OutOfMemoryError) { String msg = "TcpSocketLink OutOfMemory"; ShutdownSystem.shutdownOutOfMemory(msg); } if (location != null || !lookupErrorPage) { } else if (rootExn instanceof LineMapException && rootExn instanceof ServletException && !(rootExn instanceof LineCompileException) && rootExn.getCause() != null) { // hack to deal with JSP wrapping } else if (!isServletException) { // SRV.9.9.2 Servlet 2.4 // location = getErrorPage(rootExn, ServletException.class); location = getErrorPage(rootExn); isServletException = true; } else { location = getErrorPage(rootExn); lookupErrorPage = false; } if (location != null) lookupErrorPage = false; if (isBadRequest) break; Throwable cause = null; if (rootExn instanceof ServletException && !(rootExn instanceof LineCompileException)) cause = ((ServletException) rootExn).getRootCause(); else { lookupErrorPage = false; cause = rootExn.getCause(); } if (cause != null) rootExn = cause; else { break; } } if (location == null && lookupErrorPage) { location = getErrorPage(rootExn); } if (location == null) location = getErrorPage(500); if (isBadRequest) { // server/05a0, server/0532 if (rootExn instanceof CompileException) title = rootExn.getMessage(); else title = String.valueOf(rootExn); doStackTrace = false; isBadRequest = true; if (request instanceof CauchoRequest) ((CauchoRequest) request).killKeepalive("bad request: " + rootExn); response.resetBuffer(); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); /* * if (location == null) log.warn(e.toString()); */ } else if (rootExn instanceof UnavailableException) { UnavailableException unAvail = (UnavailableException) rootExn; if (unAvail.isPermanent()) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); title = "404 Not Found"; if (location == null) location = getErrorPage(HttpServletResponse.SC_NOT_FOUND); } else { response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); title = "503 Unavailable"; if (unAvail.getUnavailableSeconds() > 0) response.setIntHeader("Retry-After", unAvail.getUnavailableSeconds()); if (location == null) location = getErrorPage(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } } else { response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } if (location == null) location = _defaultLocation; if (log.isTraceEnabled()) log.trace(e.toString(), e); else if (isCompileException) { if (isBadRequest) log.trace(BadRequestException.class.getSimpleName() + ": " + compileException.getMessage()); else log.trace(compileException.getMessage()); } else if (!doStackTrace) log.trace(rootExn.toString()); else log.trace(e.toString(), e); if (location != null) { if (errorPageExn == null) errorPageExn = rootExn; request.setAttribute(JSP_EXCEPTION, errorPageExn); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, errorPageExn); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, errorPageExn.getClass()); if (request instanceof HttpServletRequest) request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, ((HttpServletRequest) request).getRequestURI()); String servletName = getServletName(request); if (servletName != null) request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, servletName); request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, new Integer(500)); request.setAttribute(RequestDispatcher.ERROR_MESSAGE, errorPageExn.getMessage()); try { RequestDispatcher disp = null; // can't use filters because of error pages due to filters // or security. WebApp webApp = getWebApp(); if (webApp != null) disp = webApp.getRequestDispatcher(location); else if (_host != null) disp = _host.getWebAppContainer().getRequestDispatcher(location); if (disp != null) { ((RequestDispatcherImpl) disp).error(request, response); return; } } catch (Throwable e1) { log.info(e1.toString(), e1); rootExn = e1; } } response.setContentType("text/html"); String encoding = CharacterEncoding.getLocalEncoding(); if (encoding != null) response.setCharacterEncoding(encoding); else { Locale locale = Locale.getDefault(); if (!"ISO-8859-1".equals(Encoding.getMimeName(locale))) response.setLocale(Locale.getDefault()); else response.setCharacterEncoding("utf-8"); } PrintWriter out; try { out = response.getWriter(); } catch (IllegalStateException e1) { log.trace(e1.toString(), e1); out = new PrintWriter(new OutputStreamWriter(response.getOutputStream())); } if (isDevelopmentModeErrorPage()) { out.println("<html>"); if (!response.isCommitted()) out.println("<head><title>" + escapeHtml(title) + "</title></head>"); out.println("<body>"); out.println("<h1>" + escapeHtml(title) + "</h1>"); out.println("<code><pre>"); if (debug && !CurrentTime.isTest()) doStackTrace = true; if (doStackTrace) { out.println("<script language='javascript' type='text/javascript'>"); out.println("function show() { document.getElementById('trace').style.display = ''; }"); out.println("</script>"); out.print("<a style=\"text-decoration\" href=\"javascript:show();\">[show]</a> "); } if (compileException instanceof DisplayableException) { // ioc/0000 // XXX: dispExn.print doesn't normalize user.name // dispExn.print(out); out.println(escapeHtml(compileException.getMessage())); } else if (compileException != null) out.println(escapeHtml(compileException.getMessage())); else out.println(escapeHtml(rootExn.toString())); if (doStackTrace) { out.println("<span id=\"trace\" style=\"display:none\">"); printStackTrace(out, lineMessage, e, rootExn, lineMap); out.println("</span>"); } /* * if (doStackTrace || debug) { printStackTrace(out, lineMessage, e, rootExn, lineMap); } */ out.println("</pre></code>"); printVersion(out); out.println("</body></html>"); } else { // non-development mode out.println("<html>"); out.println("<title>Server Error</title>"); out.println("<body>"); out.println("<h1>Server Error</h1>"); out.println("<p>The server is temporarily unavailable due to an"); out.println("internal error. Please notify the system administrator"); out.println("of this problem.</p>"); out.println("<pre><code>"); out.println("Date: " + QDate.formatISO8601(CurrentTime.getCurrentTime())); out.println("</code></pre>"); printVersion(out); out.println("</body></html>"); } String userAgent = request.getHeader("User-Agent"); if (userAgent != null && userAgent.indexOf("MSIE") >= 0) { out.print(MSIE_PADDING); } out.close(); }
From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java
private void doDispatch(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation) throws ServletException, IOException { // ,responsebuffer,TODO: need resetBuffer()? response.resetBuffer(); // Set the invocation into HttpServlerRequestImpl if (request instanceof HttpServletRequestImpl) { ((HttpServletRequestImpl) request).setInvocation(_dispatchInvocation); ((HttpServletRequestImpl) request).setDispatcherType(DispatcherType.REQUEST); }/*from w ww . j ava 2s. c o m*/ boolean isValid = false; try { invocation.getFilterChainInvocation().service(request, response); isValid = true; } finally { if (request.getAsyncContext() != null) { // An async request was started during the forward, don't close the // response as it may be written to during the async handling return; } // server/106r, ioc/0310 if (isValid) { finishResponse(response); } } }
From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java
private void doForward(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation) throws ServletException, IOException { // Reset any output that has been buffered, but keep headers/cookies response.resetBuffer(); // Servlet-3_1-PFD 9.4 //Wrap the request ForwardRequest wrequest = new ForwardRequest(request, response, invocation); // If we have already been forwarded previously, then keep using the established // original value. Otherwise, this is the first forward and we need to establish the values. // Note: the established value on the original request for pathInfo and // for queryString is allowed to be null, but cannot be null for the other values. if (request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI) == null) { // ??,/*from w w w . j ava 2 s . c o m*/ wrequest.setAttribute(RequestDispatcher.FORWARD_REQUEST_URI, request.getRequestURI()); wrequest.setAttribute(RequestDispatcher.FORWARD_CONTEXT_PATH, request.getContextPath()); wrequest.setAttribute(RequestDispatcher.FORWARD_SERVLET_PATH, request.getServletPath()); wrequest.setAttribute(RequestDispatcher.FORWARD_PATH_INFO, request.getPathInfo()); wrequest.setAttribute(RequestDispatcher.FORWARD_QUERY_STRING, request.getQueryString()); } boolean isValid = false; try { invocation.getFilterChainInvocation().service(wrequest, response); isValid = true; } finally { if (request.getAsyncContext() != null) { // An async request was started during the forward, don't close the // response as it may be written to during the async handling return; } // server/106r, ioc/0310 if (isValid) { finishResponse(response); } } }
From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java
private void doError(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation) throws ServletException, IOException { // Reset any output that has been buffered, but keep headers/cookies response.resetBuffer(); // Servlet-3_1-PFD 9.4 //Wrap the request ErrorRequest wrequest = new ErrorRequest(request, response, invocation); boolean isValid = false; try {/* w w w. j a v a 2 s. c o m*/ invocation.getFilterChainInvocation().service(wrequest, response); isValid = true; } finally { if (request.getAsyncContext() != null) { // An async request was started during the forward, don't close the // response as it may be written to during the async handling return; } // server/106r, ioc/0310 if (isValid) { finishResponse(response); } } }