HowTomcatWorks 第五章
The SimpleContext class represents a context. It uses the SimpleContextMapper as its mapper and SimpleContextValve as its basic valve. Two valves, ClientIPLoggerValve and HeaderLoggerValve, are added to the context. Two wrappers, each represented by SimpleWrapper, are added as child containers of the context. The wrappers use SimpleWrapperValve as their basic valve but do not have additional valves.
The Context application uses the same loader and the two valves. However, the loader and valves are associated with the context, not a wrapper. This way, the loader can be used by both wrappers. The context is assigned as the container for the connector. Therefore, the connector will call the invoke method of the context every time it receives an HTTP request. The rest is not hard to figure out if you recall our discussion above:
1. A container has a pipeline. The container's invoke method calls the pipeline's invoke method.
2. The pipeline's invoke method invokes all the valves added to its container and then calls its basic valve's invoke method.
3. In a wrapper, the basic valve is responsible to load the associated servlet class and respond to the request.
4. In a context with child containers, the basic valve uses a mapper to find a child container that is responsible for processing the request. If a child container is found, it calls the invoke method of the child container. It then goes back to Step 1.
Now let's see the order of processing in the implementation. The SimpleContext class's invoke method calls the pipeline's invoke method.
public void invoke(Request request, Response response) throws IOException, ServletException {
pipeline.invoke(request, response);
}
The pipeline is represented by the SimplePipeline class. Its invoke method is as follows.
public void invoke(Request request, Response response) throws IOException, ServletException { // Invoke the first Valve in this pipeline for this request
(new SimplePipelineValveContext()).invokeNext(request, response);
}
第六章
第8章 类装载器
Starting from J2SE 1.2, the JVM employs three class loaders: bootstrap class loader, extension class loader, and system class loader.
Each of the three class loaders has a parent-child relationship with each other, in which the bootstrap class loader sits at the top of the hierarchy and the system class loader at the bottom.
The bootstrap class loader is used to bootstrap the JVM. It starts working whenever you call the java.exe program. As such, it must be implemented using the native code because it is used to load the classes required for the JVM to function. Also, it is responsible for loading all the core Java classes, such as those in java.lang and java.io packages. The bootstrap class loader searches the core libraries such as rt.jar, i18n.jar, etc. Which libraries are searched depends on the version of the JVM and the operating system.
The extension class loader is responsible for loading classes in a standard extension directory. This is to make the programmer's life easier because they can just copy JAR files into this extension directory and the jar files will be searched automatically.
The extension library differs from one vendor to another. Sun's JVM's standard extension directory is /jdk/jre/lib/ext.
The system class loader is the default class loader and searches the directories and JAR files specified in the CLASSPATH environment variable.
第9章 Session Manager
第10章 Security
A realm is a component used for authenticating a user. It can tell you whether or not a pair of user name and password is valid.
A principal is represented by the java.security.Principal interface. Its implementation in Catalina is the org.apache.catalina.realm.GenericPrincipal class
第11章 StandardWrapper