This class diagram is the method and property of the most important class that I intercept.
Where Protocalhandler is the protocol processor, Tomcat supports the protocols that are seen in the following ways. Different protocols implement different Protocalhandler classes.
Public voidSetprotocol (String protocol) {if(Aprlifecyclelistener.isapravailable ()) {if("http/1.1". Equals (protocol)) {Setprotocolhandlerclassname ("Org.apache.coyote.http11.Http11AprProtocol"); } Else if("ajp/1.3". Equals (protocol)) {Setprotocolhandlerclassname ("Org.apache.coyote.ajp.AjpAprProtocol"); } Else if(Protocol! =NULL) {setprotocolhandlerclassname (protocol); } Else{setprotocolhandlerclassname ("Org.apache.coyote.http11.Http11AprProtocol"); } } Else { if("http/1.1". Equals (protocol)) {Setprotocolhandlerclassname ("Org.apache.coyote.http11.Http11NioProtocol"); } Else if("ajp/1.3". Equals (protocol)) {Setprotocolhandlerclassname ("Org.apache.coyote.ajp.AjpNioProtocol"); } Else if(Protocol! =NULL) {setprotocolhandlerclassname (protocol); } } }
View Code
Protocalhandler is the core of the entire connector class.
When initializing the connector, the processor object is created according to the protocol name.
PublicConnector (String protocol) {Setprotocol (protocol); //Instantiate protocol HandlerProtocolhandler p =NULL; Try{Class<?> Clazz =Class.forName (protocolhandlerclassname); P=(Protocolhandler) clazz.newinstance (); } Catch(Exception e) {log.error (sm.getstring ("Coyoteconnector.protocolhandlerinstantiationfailed"), E); } finally { This. Protocolhandler =p; } if(!globals.strict_servlet_compliance) {uriencoding= "UTF-8"; Uriencodinglower=uriencoding.tolowercase (locale.english); } }
View Code
The first is to initialize the Protocol processor (remove the less important code)
protected void throws lifecycleexception { super. initinternal (); // Initialize Adapter New Coyoteadapter (this); Protocolhandler.setadapter (adapter);
Each protocol processor has a corresponding adapter, what does the adapter do? protocolhandler.init (); }
Connector boot, actually start the corresponding protocol processor,
protected voidStartinternal ()throwslifecycleexception {//Validate settings before starting if(Getport () < 0) { Throw Newlifecycleexception (sm.getstring ("Coyoteconnector.invalidport", Integer.valueof (Getport ())); } setState (lifecyclestate.starting); Try{Protocolhandler.start (); } Catch(Exception e) {String Errprefix= ""; if( This. Service! =NULL) {Errprefix+ = "service.getname (): \" "+ This. Service.getname () + "\"; "; } Throw Newlifecycleexception (Errprefix+ " " +sm.getstring ("Coyoteconnector.protocolhandlerstartfailed"), E); } }
View Code
Termination is actually terminating the Protocol processor
protected voidStartinternal ()throwslifecycleexception {//Validate settings before starting if(Getport () < 0) { Throw Newlifecycleexception (sm.getstring ("Coyoteconnector.invalidport", Integer.valueof (Getport ())); } setState (lifecyclestate.starting); Try{Protocolhandler.start (); } Catch(Exception e) {String Errprefix= ""; if( This. Service! =NULL) {Errprefix+ = "service.getname (): \" "+ This. Service.getname () + "\"; "; } Throw Newlifecycleexception (Errprefix+ " " +sm.getstring ("Coyoteconnector.protocolhandlerstartfailed"), E); } }
View Code
You see here, actually see the connector class need to do the following work
(1) Create a Request object
/** * Create (or allocate) and return a request object suitable for * Specifying the contents of a request to the Responsible Container. */ Public Request createrequest () { new request (); Request.setconnector (this); return (request); }
(2) Create a Response object
/** * Create (or allocate) and return a Response object suitable for * receiving the contents of a Response from The responsible Container. */ Public Response Createresponse () { new Response (); Response.setconnector (this); return (response); }
(3) to the two objects to the container, simply speaking, after creating the good object, passed to the adapter class is OK. Coyoteadapter class
Tomcat 7 Connector Intensive (1)