- 浏览: 204647 次
- 性别:
- 来自: 福建省
文章分类
最新评论
-
c929833623:
...
Mysql JDBC驱动源码分析(Statement,ResultSet的创建)四 -
pythonlord:
顶 很有帮助,感谢楼主,好人一生平安
Mysql JDBC驱动源码分析(加载驱动)一 -
kiaonly:
代码有错误,我戳。
解释器模式(Interpreter)---java与模式(例子) -
wyzxzws:
小鸟学习了!
JAVA编码问题记录 -
xiaotao.2010:
写的不错! 弱弱说一句 建议使用URL二次转码, 这样可以避免 ...
JAVA编码问题记录
一,这一章节主要讲request与response通过管道,阀门在各个容器间运行
1,connector.getContainer().getPipeline().getFirst().invoke(request, response);
这一步是StandardEngine获取StandardPipeline被StandardEngineValve进行过滤后执行到StandardHost
public final void invoke(Request request, Response response) throws IOException, ServletException { // Select the Host to be used for this Request Host host = request.getHost(); if (host == null) { response.sendError (HttpServletResponse.SC_BAD_REQUEST, sm.getString("standardEngine.noHost", request.getServerName())); return; } // Ask this Host to process this request //这个是StandardHost通过管道要到下一个容器去 //Host要经过两个阀门由这里的ErrorReportValve与下一个的StandarHostValve host.getPipeline().getFirst().invoke(request, response); }
以下到了ErrorReportValve#invoke
/** * Invoke the next Valve in the sequence. When the invoke returns, check * the response state, and output an error report is necessary. * * @param request The servlet request to be processed * @param response The servlet response to be created * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet error occurs */ public void invoke(Request request, Response response) throws IOException, ServletException { // Perform the request //StandHostValve阀门的执行 getNext().invoke(request, response); Throwable throwable = (Throwable) request.getAttribute(Globals.EXCEPTION_ATTR); if (response.isCommitted()) { return; } if (throwable != null) { // The response is an error response.setError(); // Reset the response (if possible) try { response.reset(); } catch (IllegalStateException e) { ; } response.sendError (HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } response.setSuspended(false); try { report(request, response, throwable); } catch (Throwable tt) { ; } }
再执行StandardHostValve#invoke
public final void invoke(Request request, Response response) throws IOException, ServletException { // Select the Context to be used for this Request //容器StandardContext Context context = request.getContext(); if (context == null) { response.sendError (HttpServletResponse.SC_INTERNAL_SERVER_ERROR, sm.getString("standardHost.noContext")); return; } // Bind the context CL to the current thread if( context.getLoader() != null ) { // Not started - it should check for availability first // This should eventually move to Engine, it's generic. //把WebappClassLoader设置进线程 Thread.currentThread().setContextClassLoader (context.getLoader().getClassLoader()); } // Ask this Context to process this request //下一个管道StandardContextValve context.getPipeline().getFirst().invoke(request, response); // Access a session (if present) to update last accessed time, based on a // strict interpretation of the specification if (Globals.STRICT_SERVLET_COMPLIANCE) { request.getSession(false); } // Error page processing //页面错误进行暂停 response.setSuspended(false); Throwable t = (Throwable) request.getAttribute(Globals.EXCEPTION_ATTR); if (t != null) { throwable(request, response, t); } else { // status(request, response); } // Restore the context classloader Thread.currentThread().setContextClassLoader (StandardHostValve.class.getClassLoader()); }
执行到了StandContextValve#invoke
/** * Select the appropriate child Wrapper to process this request, * based on the specified request URI. If no matching Wrapper can * be found, return an appropriate HTTP error. * * @param request Request to be processed * @param response Response to be produced * @param valveContext Valve context used to forward to the next Valve * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ public final void invoke(Request request, Response response) throws IOException, ServletException { // Disallow any direct access to resources under WEB-INF or META-INF //不允许访问以下两个目录的资源文件 MessageBytes requestPathMB = request.getRequestPathMB(); if ((requestPathMB.startsWithIgnoreCase("/META-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/META-INF")) || (requestPathMB.startsWithIgnoreCase("/WEB-INF/", 0)) || (requestPathMB.equalsIgnoreCase("/WEB-INF"))) { notFound(response); return; } // Wait if we are reloading boolean reloaded = false; while (context.getPaused()) { reloaded = true; try { Thread.sleep(1000); } catch (InterruptedException e) { ; } } // Reloading will have stopped the old webappclassloader and // created a new one if (reloaded && context.getLoader() != null && context.getLoader().getClassLoader() != null) { Thread.currentThread().setContextClassLoader( context.getLoader().getClassLoader()); } // Select the Wrapper to be used for this Request //获取StandardWrapper,这个不允许有子容器 Wrapper wrapper = request.getWrapper(); if (wrapper == null) { notFound(response); return; } else if (wrapper.isUnavailable()) { // May be as a result of a reload, try and find the new wrapper wrapper = (Wrapper) container.findChild(wrapper.getName()); if (wrapper == null) { notFound(response); return; } } // Normal request processing Object instances[] = context.getApplicationEventListeners(); ServletRequestEvent event = null; if ((instances != null) && (instances.length > 0)) { event = new ServletRequestEvent (((StandardContext) container).getServletContext(), request.getRequest()); // create pre-service event for (int i = 0; i < instances.length; i++) { if (instances[i] == null) continue; if (!(instances[i] instanceof ServletRequestListener)) continue; ServletRequestListener listener = (ServletRequestListener) instances[i]; try { listener.requestInitialized(event); } catch (Throwable t) { container.getLogger().error(sm.getString("standardContext.requestListener.requestInit", instances[i].getClass().getName()), t); ServletRequest sreq = request.getRequest(); sreq.setAttribute(Globals.EXCEPTION_ATTR,t); return; } } } //StandardWrapperValve的执行,这下对servlet,filter,listener进行了处理 wrapper.getPipeline().getFirst().invoke(request, response); if ((instances !=null ) && (instances.length > 0)) { // create post-service event for (int i = 0; i < instances.length; i++) { if (instances[i] == null) continue; if (!(instances[i] instanceof ServletRequestListener)) continue; ServletRequestListener listener = (ServletRequestListener) instances[i]; try { listener.requestDestroyed(event); } catch (Throwable t) { container.getLogger().error(sm.getString("standardContext.requestListener.requestDestroy", instances[i].getClass().getName()), t); ServletRequest sreq = request.getRequest(); sreq.setAttribute(Globals.EXCEPTION_ATTR,t); } } } }
发表评论
-
Nginx1.1实现Resin4集群
2011-10-17 17:56 7220一,web服务器小论 以前的公司使用的web服务器是to ... -
Apache实现Tomcat集群
2010-06-08 20:14 1393一,配置介绍 1,linux 2,tomcat6. ... -
Tomcat源码---容器生命周期管理(Lifecycle)一
2010-03-31 11:12 4418一,tomcat中每一个容器 ... -
Tomcat源码---Session的分析一
2010-03-29 11:31 3796一,前面看了大致的tomcat的请求/响应,接下来的文章对to ... -
Tomcat源码---响应处理五
2010-03-25 16:01 1785一,响应工作我们应该从CoyoteAdapter#servic ... -
Tomcat源码---请求处理四(2)
2010-03-25 15:34 1586对以上的StandardWrapperValve#invok ... -
Tomcat源码---请求处理四(1)
2010-03-25 11:08 1618一,现在到了StandardWrapperValve# ... -
Tomcat源码---请求处理二
2010-03-24 15:04 1798一,经过以上文章(JIoEndpoint$Worker#run ... -
Tomcat源码---请求处理(接收,线程分配)一
2010-03-24 14:34 2790一,在以上文章中tomcat启动已经完毕,接着要做的是消息的请 ... -
Tomcat源码---容器启动六(4)
2010-03-24 11:14 1404现在容器已经启动成功的StanderService#start ... -
Tomcat源码---容器启动六(3)
2010-03-24 10:48 2256一,容器已经启动到部暑文件(webapps),接下去是Stan ... -
Tomcat源码---容器启动六(2)
2010-03-23 16:42 1458super.start()--->org.apach ... -
Tomcat源码---容器启动六(1)
2010-03-22 16:02 1457一,完成了以上的初始化工作,现在进行容器的启动工作由 ... -
Tomcat源码---初始化容器五
2010-03-22 15:03 1779一,上面文章完成了对server.xml载入以及解析,现在主要 ... -
Tomcat源码---载入相应的资源及解析四(2)
2010-03-19 16:47 1468一,根据以上文章所讲的对server.xml的解析作下简单的分 ... -
Tomat源码---载入相应的资源及解析四(1)
2010-03-19 16:22 1370一,进行了以上的类包加载后,现在主要的工作是载入server. ... -
Tomcat源码---启动.初始化(加载类包)分析三
2010-03-19 15:37 2196一,启动 Tomcat是从org.apache.catali ... -
Tomcat的简单了解二
2010-03-19 14:40 1802在查看源代码时,在网上找了一系列的文章,在些作详解: ... -
Tomcat中server.xml的配置分析一
2010-03-19 14:07 1784最近查看了tomcat6的源代码,了解了里面的大概 ...
相关推荐
3-5Tomcat响应请求源码与nio处理请求源码实现.mp4
apache-tomcat-9.0.8 其中有完整的源码 bin目录下有你所想要的所有完整的
从零手写Tomcat【源码】【abl-tomcat-004】【基础完善-处理动态资源请求】 文章地址:https://blog.csdn.net/m0_37969197/article/details/124096403 目录地址:...
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台...
Tomcat启动流程分析 组件的生命周期管理 用Lifecycle管理启动、停止、关闭 Lifecycle接口预览 ...根据请求地址匹配正确的容器进行处理 将响应返回客户端 Container设计 Servlet容器的实现。
从零手写Tomcat【源码】【abl-tomcat-005】【添加多线程,处理请求】 文章地址:https://blog.csdn.net/m0_37969197/article/details/124098639 目录地址:...
在这里,会话被实现为非粘性的(意味着,每个请求都可以转到集群中的任何服务器,这与Apache提供的Tomcat集群设置不同。) 请求会话将立即存储到Redis中(会话属性必须是可序列化的),以供其他服务器使用。 当...
3-8Tomcat请求容器中的处理与启动过程源码实现(1).mp4
3-8Tomcat请求容器中的处理与启动过程源码实现(2).mp4
Tomcat初始化流程分析,Tomcat启动流程分析 Tomcat处理一次请求过程分析 servlet初始化流程
对 NIO 模式,请求的流程描述的很详细。值得去仔细的研究。
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以...最新的源码供研究
NULL 博文链接:https://liudeh-009.iteye.com/blog/1563948
1.web.xml内容修改,添加servlet标签 2.添加Servlet接口与实现 3.解析web.xml 4.修改启动时逻辑,扫描全部servlet 5.Request、Response 说明 6.动态处理请求,通过反射创建Servlet 7.浏览器测试
3. 并发性改进:Tomcat 8 对并发性进行了改进,包括更好的线程管理、请求处理和响应处理等方面的优化。 4. EL 3.0支持:Tomcat 8 支持最新的EL(表达式语言)3.0规范,提供了更多的表达式功能和语言特性。 5. JSP ...
版本:apache-tomcat-9.0.88 以下是一些 Tomcat 9 中新增的主要功能: 1. Servlet 4.0支持:Tomcat 9...6. WebSocket子协议支持:Tomcat 9 支持对 WebSocket 子协议的处理,允许服务器和客户端之间传输更多类型的数据。
Tomcat是一款servlet服务器,它能够接受请求,处理请求并给出响应。
requestProcess.pdf-Tomcat请求处理流程序列图(2014.10.28-2014.10.29) 架构/-Tomcat服务器的架构结构和设计(2014.10.29-2014.10.29) server.xml-Tomcat容器配置文件(2014.10.29-) config /-Tomcat配置引用...
资源是关于tomcat深入剖析的源码. 本书深入剖析Tomcat 4和Tomcat 5中的每个组件,并揭示其内部工作原理。通过学习本书,你将可以自行开发Tomcat组件,或者扩展已有的组件。 Tomcat是目前比较流行的Web服务器之一。...
java雷电飞机源码 http服务&ajax编程,请求和响应信息解析,json数据格式 1. 服务器 通俗的讲,能够提供某种服务的机器(计算机)称为服务器 1.2 服务器软件 使计算机能提供某种服务的应用软件,称之为服务器软件. ...