Coder 爱翻译 How Tomcat Works 第五章 第一部分
Chapter 5: Container
一个容器是一个为servlet处理请求和给客户端填充response对象的模块。一个容器可以用
org.apache.catalina.Container接口表示。这里有四种类型的容器:Engine, Host, Context 和Wrapper。这章包含了Context和Wrapper。把其它两个容器放在后面第十三章讲解。
The Container Interface
一个容器必须实现了org.apache.catalina.Container。你看到了在第四章中,你传递一个Container实例给连接器的toContainer方法,这样连接器可以调用容器的invoke方法。回顾下面的Bootstrap类的代码:
Listing 5.2: The StandardValveContext class in Tomcat 5 package org.apache.catalina.core; import java.io.IOException; import javax.servlet.ServletException; import org.apache.catalina.Request; import org.apache.catalina.Response; import org.apache.catalina.Valve; import org.apache.catalina.ValveContext; import org.apache.catalina.util.StringManager; public final class StandardValveContext implements ValveContext { protected static StringManager sm = StringManager.getManager(Constants.Package); protected String info = "org.apache.catalina.core.StandardValveContext/1.0"; protected int stage = 0; protected Valve basic = null; protected Valve valves[] = null; public String getInfo() { return info; } public final void invokeNext(Request request, Response response) throws IOException, ServletException { int subscript = stage; stage = stage + 1; // Invoke the requested Valve for the current request thread if (subscript < valves.length) { valves[subscript].invoke(request, response, this); } else if ((subscript == valves.length) && (basic != null)) { basic.invoke(request, response, this); } else { throw new ServletException (sm.getString("standardPipeline.noValve")); } } void set(Valve basic, Valve valves[]) { stage = 0; this.basic = basic; this.valves = valves; } }