Tomcat Launcher (vi) Catalina Analysis-standardserver.start ()
The previous analysis to: Http11nioprocessor.process (socketwrapper<s> socketwrapper) will convert the request to generate requests, and response objects, Then call Coyoteadapter.service (Request,response) to pass the request to the corresponding context
Initialize constructor method
Public Http11nioprocessor (intboolean rejectillegalheadername, int Maxtrailersize, set<string> allowedtrailerheaders, intint maxswallowsize)
Http11nioprocessor This object generation is generated by Createprocessor ().
Org.apache.coyote.http11.Http11NioProtocol.Http11ConnectionHandler.createProcessor ()
@Override Public http11nioprocessor createprocessor () { new http11nioprocessor ( Proto.getmaxhttpheadersize (), Proto.getrejectillegalheadername (), (Nioendpoint) Proto.endpoint, Proto.getmaxtrailersize (), proto.getallowedtrailerheadersasset (), Proto.getmaxextensionsize (), Proto.getmaxswallowsize ()); Proto.configureprocessor (processor); Register (processor); return processor; }
The construction parameters are provided by the Proto object, which is the object that represents the Http11nioprotocol
para1:Private intMaxhttpheadersize = 8 * 1024;p Ara2:Private BooleanRejectillegalheadername =false;p Ara3:nioendpoint; PARA4: The maximum size, in bytes, at the end of the headerPrivate intMaxtrailersize = 8192;p Ara5: The header name that is allowed to be sent through the trailer. They are stored in lowercase form. PrivateSet<string> allowedtrailerheaders =Collections.newsetfrommap (NewConcurrenthashmap<string, boolean>());p ARA6: Maximum size of extended information in chunked encodingPrivate intMaxextensionsize = 8192;p ara7:maximum amount of request body to swallowPrivate intMaxswallowsize = 2 * 1024 * 1024;
And look at the construction method to do the god Horse
Http11nioprocessor
PublicHttp11nioprocessor (intMaxhttpheadersize,BooleanRejectillegalheadername, nioendpoint endpoint,intMaxtrailersize, set<string>Allowedtrailerheaders,intMaxextensionsize,intmaxswallowsize) { Super(endpoint); InputBuffer=NewInternalnioinputbuffer (Request, maxhttpheadersize, rejectillegalheadername); Request.setinputbuffer (InputBuffer); OutputBuffer=NewInternalniooutputbuffer (response, maxhttpheadersize); Response.setoutputbuffer (OutputBuffer); Initializefilters (Maxtrailersize, Allowedtrailerheaders, Maxextensionsize, maxswallowsize); }
Super (Endpoint)
Public Abstracthttp11processor (abstractendpoint<s> endpoint) { super(endpoint); New Userdatahelper (GetLog ()); }
Continue super (Endpoint)
public abstractprocessor (abstractendpoint<s> endpoint) { this . Endpoint = endpoint; Asyncstatemachine = new asyncstatemachine (this ); Request = new request (); Response = new response (); Response.sethook ( this ); Request.setresponse (response); Request.sethook ( this ); }
You'll find out here. The original is initialized org.apache.coyote.Request, Org.apache.coyote.Response, Internalnioinputbuffer, Internalniooutputbuffer object
InputBuffer and request match. OutputBuffer and Response match.
Attention:
Request.setinputbuffer (InputBuffer);
The InputBuffer object associated with the request is associated with the socket that our thread receives. This corresponds to the completion of the request initialization. The end will be passed to the corresponding context
After initialization, watch http11nioprocessor.process
/*** Process pipelined HTTP requests using the specified input and output * streams. * * @paramSocketwrapper Socket from which the HTTP requests would be read * and the HTTP responses would be WRI Tten. * * @throwsIOException Error during an I/O operation*/@Override PublicSocketstate Process (socketwrapper<s>socketwrapper) {Requestinfo RP=request.getrequestprocessor (); Rp.setstage (Org.apache.coyote.Constants.STAGE_PARSE); //Setting up the I/O parsing phaseSetsocketwrapper (Socketwrapper); Getinputbuffer (). Init (Socketwrapper, endpoint); Getoutputbuffer (). Init (Socketwrapper, endpoint); 。 。 。 if(!geterrorstate (). IsError ()) { //Setting up filters, and parse some request headers, preparatory phase rp.setstage (Org.apache.coyote.Constants.STAGE_PREPARE); Try{preparerequest (); }。。。 //Process the request in the adapter if(!geterrorstate (). IsError ()) { Try{、、、 Request processing phase rp.setstage (Org.apache.coyote.Constants.STAGE_SERVICE); Getadapter (). Service (request, response);.. //Finish The handling of the requestrp.setstage (Org.apache.coyote.Constants.STAGE_ENDINPUT); EndRequest ();.. The latter stage omits rp.setstage (Org.apache.coyote.Constants.STAGE_ENDOUTPUT); Rp.setstage (org.apache.coyote.Constants.STAGE_ KEEPALIVE); Rp.setstage (Org.apache.coyote.Constants.STAGE_ENDED);
From the parsing phase
Getinputbuffer (). Init (Socketwrapper, endpoint); Get InputBuffer from socket, initialize a Socketinputbuffer object to perform doread () read operations
Getoutputbuffer (). Init (Socketwrapper, endpoint); Get OutputBuffer from Socket, Initializes a Socketoutputbuffer object to perform a write operation Dowrite ()
The request processing phase. Focus
Getadapter (). Service (request, response);
This is where the request is forwarded to the corresponding context processing. Request initialization can be seen in the constructor method of the Http11nioprocessor class.
Tomcat boot (Ⅶ) Request processing--processor.process (socketwrapper<s> socketwrapper)