source analysis : how jetty starts from webapp
WebAppContext
WebAppContext is set in Server,while Server is a subclass of HandlerWrapper.
1 server.start()
1.1 doStart()
1.1.1 super.doStart(), the HandlerWrapper will help to call the handler of the wrapper. As the figure1.1 shows.
Figure 1.1 org.eclipse.jetty.server.handler.HandlerWrapper.doStart()
1.1.1.1 WebAppContext.doStart()
Figure 1.2 org.eclipse.jetty.webapp.WebAppContext.doStart()
1.1.1.1.1 WebAppContext.preConfigure() do something, including loading configuration, loading system classes, loading server classes. And at last, it call the configurations to preconfigure theirselves. See figure 1.3
Figure 1.3 org.eclipse.jetty.webapp.WebAppContext.preConfigure()
1.1.1.1.1.1 WebAppContext.loadConfigurations() load all configuration classes.
Figure 1.4 org.eclipse.jetty.webapp.WebAppContext.loadConfigurations()
1.1.1.1.1.1.1 _configurationClasses=_dftconfigurationClasses point out that default configuration will be used if not special configuration classes assigned. The default configuration classes are as figure 1.5 shows:
Figure 1.5 the default configuration classes
1.1.1.1.1.2 WebXmlConfiguration.preConfigure() as a default configuration class, load and parse the web.xml file ready. See figure 1.6
Figure 1.6 loads web.xml
#findWebXml() will load the web.xml file, and setWebXml() to context.getMetaData() will finish to parse the web.xml file for latter use.
Now configration loading is finished.
1.1.1.1.2 ContextHandler.doStart() the main job for dostart() is to invoke startContext(), while startContext() is override by WebAppContext
1.1.1.1.2.1 WebAppContext.startContext() the main job is to configure() and resolve() the metadata. DescriptorProcessor will process the web.xml while resolving, whick is set in configure().
Figure 1.7
Following paragraph will explain how StandardDescriptorProcessor, implementation of DescriptorProcessor to process the web.xml file.
1.1.1.1.2.1.1 WebAppContext.cofigure() will invoke the configure() method of each configuration classes which mentioned in 1.1.1.1.1.2 WebAppContext.preConfigure(). DescriptorProcessor are set into Metadata for latter use. StandardDescriptorProcessor indeed is the implementation of DescriptorProcessor set into Metadata. While initializing StandardDescriptorProcessor, methods are registered to _visitors, which point out how to deal with servrals of web setting, including web.xml file’s.
Figure 1.8 register method to _visitors
1.1.1.1.2.1.2 MetaData.resolve() shows that how web.xml and other cofigurations are process. Web.xml will be explained only to simplify the learning.
Figure 1.9
1.1.1.1.2.1.2.1 IterativeDescriptor.process() as the class name shows, interate each xml node and visitor the registered processor method.
Figure 1.10
In fact, there are many case, since the web setting is a little complex which is specified in JSR340 for servlet 2.5 version. For time saving and target shooting, only servlet and filter and explain as follows:
1.1.1.1.2.1.2.1.1 StandardDescriptorProcessor.visitServlet() add a new servletholder which holds a really servlet, into the ServletHandler of context.
Figure 1.11
1.1.1.1.2.1.2.1.2 StandardDescriptorProcessor.visitFilter() add a new filterholder which holds a really filter, into the ServerHandler of context.
Figure 1.12
According to previous explain, all steps of web setting are covered.
Next section will explain how context works to fulfill JSR340.
浙公网安备 33010602011771号