Introduction to Tomcat
2019-09-23
[Tomcat source code](https://github.com/apache/tomcat)
Reading the Tomcat source code Tomcat architecture
What This Covers
- Tomcat structure diagram
- Tomcat startup process
- Tomcat request handling process
1. Tomcat structure
- Service
- Connector
- Container
- Engine
- Host
- Context
- Wrapper: corresponds to one Servlet class
- Context
- Host
- Engine
- Container
- Connector
2. Tomcat startup process
3. Tomcat request handling process
- Data arrives on a local port and is picked up by the Connector
- Connector: listens for TCP connection requests on the port
- Creates the Request and Response
- Spawns a thread to pass the request to Container.Engine
- The Container’s Engine receives the request and hands it to the Host
- The Host receives the request and hands it to the Context
- The Context receives the request, matches the Servlet, and hands it over
- Constructs the HttpServletRequest and HttpServletResponse
- Context returns the HttpServletResponse to the Host
- The Context receives the request, matches the Servlet, and hands it over
- Host returns the HttpServletResponse to the Engine
- The Host receives the request and hands it to the Context
- Engine returns the HttpServletResponse to the Connector
- The Container’s Engine receives the request and hands it to the Host
- Connector returns the HttpServletResponse to the Browser
- Connector: listens for TCP connection requests on the port