requestdispatcherimpl.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 564 行 · 第 1/2 页
JAVA
564 行
try { if (response != null) { response.setRequest(subRequest); response.setResponseStream(response.getOriginalStream()); } res.resetBuffer(); res.setContentLength(-1); invocation.service(topRequest, res); if (cauchoRes != null) cauchoRes.close(); else { // server/10ab try { PrintWriter out = res.getWriter(); if (out != null) out.close(); } catch (IllegalStateException e1) { } try { OutputStream os = res.getOutputStream(); if (os != null) os.close(); } catch (IllegalStateException e) { } // server/1732 wants this commented out /* // TCK wants the code (test?) ServletResponse ptr = res; while (ptr instanceof HttpServletResponseWrapper) { ptr = ((HttpServletResponseWrapper) ptr).getResponse(); if (ptr instanceof AbstractHttpResponse) { ((AbstractHttpResponse) ptr).finish(); break; } } */ } } finally { subRequest.finish(); thread.setContextClassLoader(oldLoader); if (response != null) { response.setRequest(oldRequest); response.setResponseStream(oldStream); //response.setWriter(oldWriter); } DispatchRequest.free(subRequest); if (reqWrapper != null) reqWrapper.setRequest(parentRequest); // XXX: are these necessary? if (oldUri != null) req.setAttribute(REQUEST_URI, oldUri); if (oldContextPath != null) req.setAttribute(CONTEXT_PATH, oldContextPath); if (oldServletPath != null) req.setAttribute(SERVLET_PATH, oldServletPath); if (oldPathInfo != null) req.setAttribute(PATH_INFO, oldPathInfo); if (oldQueryString != null) req.setAttribute(QUERY_STRING, oldQueryString); if (oldForward == null) req.removeAttribute("caucho.forward"); } } public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException { include(request, response, null); } /** * Include a request into the current page. */ public void include(ServletRequest request, ServletResponse response, String method) throws ServletException, IOException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse res = (HttpServletResponse) response; IncludeDispatchRequest subRequest; DispatchResponse subResponse; Invocation invocation = _includeInvocation; WebApp webApp = invocation.getWebApp(); String queryString = invocation.getQueryString(); if (method == null) method = req.getMethod(); if (! "POST".equals(method)) method = "GET"; HttpServletRequest parentRequest = req; HttpServletRequestWrapper reqWrapper = null; HttpServletResponse parentResponse = res; HttpServletResponseWrapper resWrapper = null; if (! _webApp.getDispatchWrapsFilters()) { if (req instanceof HttpServletRequestWrapper && ! (req instanceof CauchoRequest)) { reqWrapper = (HttpServletRequestWrapper) req; parentRequest = (HttpServletRequest) reqWrapper.getRequest(); } if (res instanceof HttpServletResponseWrapper && ! (res instanceof CauchoResponse)) { resWrapper = (HttpServletResponseWrapper) res; parentResponse = (HttpServletResponse) resWrapper.getResponse(); } } subRequest = IncludeDispatchRequest.createDispatch(); WebApp oldWebApp; if (req instanceof CauchoRequest) oldWebApp = ((CauchoRequest) req).getWebApp(); else oldWebApp = (WebApp) webApp.getContext(req.getContextPath()); subRequest.init(invocation, webApp, oldWebApp, parentRequest, parentResponse, method, req.getRequestURI(), req.getServletPath(), req.getPathInfo(), req.getQueryString(), queryString); HttpServletRequest topRequest = subRequest; if (reqWrapper != null) { reqWrapper.setRequest(subRequest); topRequest = reqWrapper; } subResponse = DispatchResponse.createDispatch(); subResponse.setNextResponse(res); AbstractResponseStream s = null; boolean oldDisableClose = false; subResponse.init(subRequest); subResponse.setNextResponse(parentResponse); subResponse.start(); subResponse.setCharacterEncoding(res.getCharacterEncoding()); if (_webApp.getDispatchWrapsFilters()) subResponse.setCauchoResponseStream(true); CauchoResponse cauchoRes = null; if (res instanceof CauchoResponse) { cauchoRes = (CauchoResponse) res; } else if (! _webApp.getDispatchWrapsFilters()) { subResponse.killCache(); } HttpServletResponse topResponse = subResponse; if (resWrapper != null) { resWrapper.setResponse(subResponse); topResponse = res; } Object oldUri = null; Object oldContextPath = null; Object oldServletPath = null; Object oldPathInfo = null; Object oldQueryString = null; oldUri = req.getAttribute(REQUEST_URI); if (oldUri != null) { oldContextPath = request.getAttribute(CONTEXT_PATH); oldServletPath = req.getAttribute(SERVLET_PATH); oldPathInfo = req.getAttribute(PATH_INFO); oldQueryString = req.getAttribute(QUERY_STRING); } subRequest.setPageURI(invocation.getURI()); subRequest.setAttribute(REQUEST_URI, invocation.getURI()); String contextPath; if (webApp != null) contextPath = webApp.getContextPath(); else contextPath = null; subRequest.setPageContextPath(contextPath); subRequest.setAttribute(CONTEXT_PATH, contextPath); subRequest.setPageServletPath(invocation.getServletPath()); subRequest.setAttribute(SERVLET_PATH, invocation.getServletPath()); subRequest.setPagePathInfo(invocation.getPathInfo()); subRequest.setAttribute(PATH_INFO, invocation.getPathInfo()); subRequest.setPageQueryString(queryString); subRequest.setAttribute(QUERY_STRING, queryString); subRequest.removeAttribute("caucho.jsp.jsp-file"); Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); boolean isOkay = false; try { invocation.service(topRequest, topResponse); isOkay = true; } finally { thread.setContextClassLoader(oldLoader); // XXX: In many cases, able to use clear()? subRequest.finish(); /* XXX: if (s != null) s.setDisableClose(oldDisableClose); */ if (oldUri != null) req.setAttribute(REQUEST_URI, oldUri); else req.removeAttribute(REQUEST_URI); if (oldContextPath != null) req.setAttribute(CONTEXT_PATH, oldContextPath); else req.removeAttribute(CONTEXT_PATH); if (oldServletPath != null) req.setAttribute(SERVLET_PATH, oldServletPath); else req.removeAttribute(SERVLET_PATH); if (oldPathInfo != null) req.setAttribute(PATH_INFO, oldPathInfo); else req.removeAttribute(PATH_INFO); if (oldQueryString != null) req.setAttribute(QUERY_STRING, oldQueryString); else req.removeAttribute(QUERY_STRING); if (! isOkay) subResponse.killCache(); subResponse.close(); /* if (! (res instanceof CauchoResponse)) { if (s != null) s.close(); } */ IncludeDispatchRequest.free(subRequest); DispatchResponse.free(subResponse); if (reqWrapper != null) reqWrapper.setRequest(parentRequest); if (resWrapper != null) resWrapper.setResponse(parentResponse); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?