首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Tomcat源码-响应处置五

2012-10-31 
Tomcat源码---响应处理五一,响应工作我们应该从CoyoteAdapter#service方法下的? public void action(Actio

Tomcat源码---响应处理五

一,响应工作我们应该从CoyoteAdapter#service方法下的

?

 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类,容器,还有其设计等....进行理解

热点排行