- 浏览: 204720 次
- 性别:
- 来自: 福建省
文章分类
最新评论
-
c929833623:
...
Mysql JDBC驱动源码分析(Statement,ResultSet的创建)四 -
pythonlord:
顶 很有帮助,感谢楼主,好人一生平安
Mysql JDBC驱动源码分析(加载驱动)一 -
kiaonly:
代码有错误,我戳。
解释器模式(Interpreter)---java与模式(例子) -
wyzxzws:
小鸟学习了!
JAVA编码问题记录 -
xiaotao.2010:
写的不错! 弱弱说一句 建议使用URL二次转码, 这样可以避免 ...
JAVA编码问题记录
一,响应工作我们应该从CoyoteAdapter#service方法下的
if (!comet) { response.finishResponse(); req.action(ActionCode.ACTION_POST_REQUEST , null); }
public void finishResponse()
throws IOException { // Writing leftover bytes outputBuffer.close(); } --------------------------------------------- public void close() throws IOException { if (closed) return; if (suspended) return; if ((!coyoteResponse.isCommitted()) && (coyoteResponse.getContentLengthLong() == -1)) { // If this didn't cause a commit of the response, the final content // length can be calculated if (!coyoteResponse.isCommitted()) { coyoteResponse.setContentLength(bb.getLength()); } } //进去客户端的发送 doFlush(false); closed = true; coyoteResponse.finish(); } --------------------------------------------------------- protected void doFlush(boolean realFlush) throws IOException { if (suspended) return; doFlush = true; if (initial) { //发送头部文件,这个会触发以下方法执行 coyoteResponse.sendHeaders(); initial = false; } if (bb.getLength() > 0) { bb.flushBuffer(); } doFlush = false; if (realFlush) { coyoteResponse.action(ActionCode.ACTION_CLIENT_FLUSH, coyoteResponse); // If some exception occurred earlier, or if some IOE occurred // here, notify the servlet with an IOE if (coyoteResponse.isExceptionPresent()) { throw new ClientAbortException (coyoteResponse.getErrorException()); } } }
进行一些准备工作
public void action(ActionCode actionCode, Object param) { if (actionCode == ActionCode.ACTION_COMMIT) { // Commit current response if (response.isCommitted()) return; // Validate and write response headers //这是发送的头部文件,可跟踪下去查看 prepareResponse(); try { outputBuffer.commit(); } catch (IOException e) { // Set error flag error = true; } } else if (actionCode == ActionCode.ACTION_ACK) { // Acknowlege request // Send a 100 status back if it makes sense (response not committed // yet, and client specified an expectation for 100-continue) if ((response.isCommitted()) || !expectation) return; inputBuffer.setSwallowInput(true); try { outputBuffer.sendAck(); } catch (IOException e) { // Set error flag error = true; } } else if (actionCode == ActionCode.ACTION_CLIENT_FLUSH) { try { outputBuffer.flush(); } catch (IOException e) { // Set error flag error = true; response.setErrorException(e); } } else if (actionCode == ActionCode.ACTION_CLOSE) { // Close // End the processing of the current request, and stop any further // transactions with the client try { outputBuffer.endRequest(); } catch (IOException e) { // Set error flag error = true; } } else if (actionCode == ActionCode.ACTION_RESET) { // Reset response // Note: This must be called before the response is committed outputBuffer.reset(); } else if (actionCode == ActionCode.ACTION_CUSTOM) { // Do nothing } else if (actionCode == ActionCode.ACTION_START) { started = true; } else if (actionCode == ActionCode.ACTION_STOP) { started = false; } else if (actionCode == ActionCode.ACTION_REQ_SSL_ATTRIBUTE ) { try { if (sslSupport != null) { Object sslO = sslSupport.getCipherSuite(); if (sslO != null) request.setAttribute (SSLSupport.CIPHER_SUITE_KEY, sslO); sslO = sslSupport.getPeerCertificateChain(false); if (sslO != null) request.setAttribute (SSLSupport.CERTIFICATE_KEY, sslO); sslO = sslSupport.getKeySize(); if (sslO != null) request.setAttribute (SSLSupport.KEY_SIZE_KEY, sslO); sslO = sslSupport.getSessionId(); if (sslO != null) request.setAttribute (SSLSupport.SESSION_ID_KEY, sslO); } } catch (Exception e) { log.warn(sm.getString("http11processor.socket.ssl"), e); } } else if (actionCode == ActionCode.ACTION_REQ_HOST_ADDR_ATTRIBUTE) { if ((remoteAddr == null) && (socket != null)) { InetAddress inetAddr = socket.getInetAddress(); if (inetAddr != null) { remoteAddr = inetAddr.getHostAddress(); } } request.remoteAddr().setString(remoteAddr); } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_NAME_ATTRIBUTE) { if ((localName == null) && (socket != null)) { InetAddress inetAddr = socket.getLocalAddress(); if (inetAddr != null) { localName = inetAddr.getHostName(); } } request.localName().setString(localName); } else if (actionCode == ActionCode.ACTION_REQ_HOST_ATTRIBUTE) { if ((remoteHost == null) && (socket != null)) { InetAddress inetAddr = socket.getInetAddress(); if (inetAddr != null) { remoteHost = inetAddr.getHostName(); } if(remoteHost == null) { if(remoteAddr != null) { remoteHost = remoteAddr; } else { // all we can do is punt request.remoteHost().recycle(); } } } request.remoteHost().setString(remoteHost); } else if (actionCode == ActionCode.ACTION_REQ_LOCAL_ADDR_ATTRIBUTE) { if (localAddr == null) localAddr = socket.getLocalAddress().getHostAddress(); request.localAddr().setString(localAddr); } else if (actionCode == ActionCode.ACTION_REQ_REMOTEPORT_ATTRIBUTE) { if ((remotePort == -1 ) && (socket !=null)) { remotePort = socket.getPort(); } request.setRemotePort(remotePort); } else if (actionCode == ActionCode.ACTION_REQ_LOCALPORT_ATTRIBUTE) { if ((localPort == -1 ) && (socket !=null)) { localPort = socket.getLocalPort(); } request.setLocalPort(localPort); } else if (actionCode == ActionCode.ACTION_REQ_SSL_CERTIFICATE) { if( sslSupport != null) { /* * Consume and buffer the request body, so that it does not * interfere with the client's handshake messages */ InputFilter[] inputFilters = inputBuffer.getFilters(); ((BufferedInputFilter) inputFilters[Constants.BUFFERED_FILTER]) .setLimit(maxSavePostSize); inputBuffer.addActiveFilter (inputFilters[Constants.BUFFERED_FILTER]); try { Object sslO = sslSupport.getPeerCertificateChain(true); if( sslO != null) { request.setAttribute (SSLSupport.CERTIFICATE_KEY, sslO); } } catch (Exception e) { log.warn(sm.getString("http11processor.socket.ssl"), e); } } } else if (actionCode == ActionCode.ACTION_REQ_SET_BODY_REPLAY) { ByteChunk body = (ByteChunk) param; InputFilter savedBody = new SavedRequestInputFilter(body); savedBody.setRequest(request); InternalInputBuffer internalBuffer = (InternalInputBuffer) request.getInputBuffer(); internalBuffer.addActiveFilter(savedBody); } }
以上是tomcat中简单的请求与响应的逻辑过程,还有很多不理解的,以后会慢慢的注释上去,之后的文章中会对其servletcontext,session,request,跳转,以及使用的lifecycle进行的日记通知还有stringmessage类,容器,还有其设计等....进行理解
发表评论
-
Nginx1.1实现Resin4集群
2011-10-17 17:56 7222一,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源码---请求处理四(2)
2010-03-25 15:34 1587对以上的StandardWrapperValve#invok ... -
Tomcat源码---请求处理四(1)
2010-03-25 11:08 1618一,现在到了StandardWrapperValve# ... -
Tomcat源码---请求处理三
2010-03-25 10:39 1320一,这一章节主要讲request与response通过管道,阀 ... -
Tomcat源码---请求处理二
2010-03-24 15:04 1798一,经过以上文章(JIoEndpoint$Worker#run ... -
Tomcat源码---请求处理(接收,线程分配)一
2010-03-24 14:34 2791一,在以上文章中tomcat启动已经完毕,接着要做的是消息的请 ... -
Tomcat源码---容器启动六(4)
2010-03-24 11:14 1408现在容器已经启动成功的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 1459一,完成了以上的初始化工作,现在进行容器的启动工作由 ... -
Tomcat源码---初始化容器五
2010-03-22 15:03 1779一,上面文章完成了对server.xml载入以及解析,现在主要 ... -
Tomcat源码---载入相应的资源及解析四(2)
2010-03-19 16:47 1469一,根据以上文章所讲的对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
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以这样认为,当在一台...
3-3Tomcat响应流程原理和源码解析.mp4
Tomcat启动流程分析 组件的生命周期管理 用Lifecycle管理启动、停止、关闭 Lifecycle接口预览 几个核心方法 Server中的init方法示例 为啥StandardServer没有init方法 LifecycleBase中的init与...
3-4Tomcat中分块传输和响应流程原理和源码(2).mp4
3-4Tomcat中分块传输和响应流程原理和源码(1).mp4
Tomcat 服务器是一个免费的开放源代码的Web 应用服务器,属于轻量级应用服务器,在中小型系统和并发访问用户不是很多的场合下被普遍使用,是开发和调试JSP 程序的首选。对于一个初学者来说,可以...最新的源码供研究
3. 并发性改进:Tomcat 8 对并发性进行了改进,包括更好的线程管理、请求处理和响应处理等方面的优化。 4. EL 3.0支持:Tomcat 8 支持最新的EL(表达式语言)3.0规范,提供了更多的表达式功能和语言特性。 5. JSP ...
包含:项目源码、数据库脚本、软件工具等,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 项目都经过严格调试,确保可以运行! 1. 技术组成 前端:...
基于Bootstrap3的响应式布局网站教程源码(五),基础入门,适合新手,有齐全的注释,详细教程参考我的博文。除了博文所写之外,我还更新了许多实用的源码。 为了防止有些人不知道怎么用,我还不厌其烦的讲解下,...
包含:项目源码、数据库脚本、软件工具等,前后端代码都在里面。 该系统功能完善、界面美观、操作简单、功能齐全、管理便捷,具有很高的实际应用价值。 项目都经过严格调试,确保可以运行! 1. 技术组成 前端:...
Tomcat是一款servlet服务器,它能够接受请求,处理请求并给出响应。