Here I will explain the tomcat7 file to facilitate understanding what Digester does when analyzing the source code.
<?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="" /> <Listener className="" /> <Listener className="" SSLEngine="on" /> <Listener className="" /> <Listener className="" /> <Listener className="" /> <Listener className="" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="" description="User database that can be updated and saved" factory="" pathname="conf/" /> </GlobalNamingResources> <Service name="Catalina"> <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="150" minSpareThreads="4"/> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8443" protocol=".http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Cluster className=""/> <Realm className=""> <Realm className="" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="" /> <Valve className="" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>
Server
In tomcat, Server represents a tomcat instance, so there will be only one Server, and it also appears as a top-level element in the configuration file. The code is as follows:
<Server port="8005" shutdown="SHUTDOWN"> 。。。 </Server>
- port, the port that listens to the shutdown command, -1 means disabling the shutdown command.
- shutdown, close the tomcat command.
Listener
Listener, used to listen for the occurrence of certain events.
<Listener className="" />
VersionLoggerListener, prints logs for tomcat, java, and operating system information at startup.
<Listener className="" />
SecurityListener, do some security checks when starting tomcat.
<Listener className="" SSLEngine="on" />
AprLifecycleListener is used to listen to Apache server-related information.
<Listener className="" />
JasperListener, Jasper 2 JSP engine, is mainly responsible for recompiling the updated jsp.
<Listener className="" />
JreMemoryLeakPreventionListener, a listener that prevents memory overflow.
<Listener className="" />
GlobalResourcesLifecycleListener, initializes the global JNDI resource defined under the element GlobalNamingResources
<Listener className="" />
ThreadLocalLeakPreventionListener, prevents ThreadLocal from overflowing the listener.
GlobalNamingResources
GlobalNamingResources defines the server's global JNDI resources. Can be referenced for all engine applications.
<GlobalNamingResources> <Resource name="UserDatabase" auth="Container" type="" description="User database that can be updated and saved" factory="" pathname="conf/" /> </GlobalNamingResources>
A JNDI is defined in the configuration file, called UserDatabase, throughconf/
The content of the user is to obtain a database used for authorized users, which is an in-memory database.
Service
<Service name="Catalina"> 。。。 </Service>
There can be multiple services under the server, and there can be multiple Connectors and an Engine under the service. The default service name here is Catalina, and there are two Connectors below: Http and AJP.
- name, the name displayed by the Service, the name must be unique.
Connector
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
The above is the Connector used to handle http requests.
- port, port number 8080.
- protocol, protocol, http protocol
- connectionTimeout, maximum waiting time for response, 20 seconds
- RedirectPort, SSL request will be redirected to port 8443
<Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
The above is to use thread pools to process http requests.
<Connector port="8443" protocol=".http11.Http11Protocol" maxThreads="150" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" />
The above processed the ssl request, and the port is 8443.
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
The above process AJP requests, and you can run tomcat and apache's http server together.
Engine
Engine is a container, and a service contains only one Engine:
<Engine name="Catalina" defaultHost="localhost"> ... </Engine>
Engine can contain more than one or more hosts. Engine maps the host name or ip in the header information of the http request to the true host.
- name, Engine name, needs to be unique.
- defaultHost, default host name
Cluster
Cluster-related configuration. Tomcat supports server clusters, which can copy the reply and context attributes of the entire cluster, or deploy a war package to all clusters.
<Cluster className=""/>
Realm
<Realm className=""> <Realm className="" resourceName="UserDatabase"/> </Realm>
Realm is a database containing user, password, and role. Realm can be defined in any container. Here, authentication is performed through the external resource UserDatabase.
Host
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="" /> <Valve className="" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host>
Host virtual host is defined under Engine. There can be multiple hosts under one Engine, and there can be multiple Context under one Host.
- name, the network name of the virtual host, must have a host name and the defaultHost of Engine.
- appBase, the root directory of the virtual host application, is webapps by default.
- unpackWARs, should the war file in the webapps directory be decompressed?
- When autoDeploy, when the value is true, tomcat will regularly check appBase and other directories to deploy new web applications and Context description files.
Value
<Valve className="" /> <Valve className="" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" />
Value here means valve, which can intercept http requests and can be defined in any container.
SingleSignOn is single sign-on, and AccessLogValve is the record of the access log.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.