Package org.apache.catalina.startup
Class ContextConfig
java.lang.Object
org.apache.catalina.startup.ContextConfig
- All Implemented Interfaces:
LifecycleListener
Startup event listener for a Context that configures the properties
of that Context, and the associated defined servlets.
- Author:
- Craig R. McClanahan
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final PropertiesThe set of Authenticators that we know how to configure.protected ContextThe Context we are associated with.protected Map<String,Authenticator> Custom mappings of login methods to authenticatorsprotected StringThe default web application's deployment descriptor location.protected static longDeployment count.protected static final LoginConfigprotected booleanFlag that indicates if at least oneHandlesTypesentry is present that represents an annotation.protected booleanFlag that indicates if at least oneHandlesTypesentry is present that represents a non-annotation.Cache of default web.xml fragments per Hostprotected final Map<ServletContainerInitializer,Set<Class<?>>> Map of ServletContainerInitializer to classes they expressed interest in.protected booleanTrack any fatal errors during startup configuration processing.protected StringOriginal docBase.protected static final StringManagerThe string resources for this package.protected final Map<Class<?>,Set<ServletContainerInitializer>> Map of Types to ServletContainerInitializer that are interested in those types. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidProcess the application classes annotations, if it exists.protected voidSet up an Authenticator automatically if required, and one has not already been configured.protected voidProcess a "before start" event for this Context.protected voidcheckHandlesTypes(JavaClass javaClass, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) For classes packaged with the web application, the class and each super class needs to be checked for a match withHandlesTypesor for an annotation that matchesHandlesTypes.protected voidProcess a "contextConfig" event for this Context.protected voidProcess a "stop" event for this Context.protected voidcontextConfig(Digester digester) Process the default configuration file, if it exists.protected DigesterCreate (if necessary) and return a Digester configured to process the context configuration descriptor for an application.protected WebXmlprotected voiddestroy()Process a "destroy" event for this Context.protected voidAdjust docBase.protected voidgenerateClassFooter(Digester digester) protected voidgenerateClassHeader(Digester digester, String packageName, String resourceName) protected InputSourceIdentify the application web.xml to be used and obtain an input source for it.protected FilegetContextXmlJavaSource(String contextXmlPackageName, String contextXmlSimpleClassName) protected static StringgetContextXmlPackageName(String generatedCodePackage, Container container) Obtain the location of the default deployment descriptor.protected booleanprotected Fileprotected Stringprotected InputSourceIdentify the default web.xml to be used and obtain an input source for it.protected Fileprotected InputSourceIdentify the host web.xml to be used and obtain an input source for it.protected booleanprotected InputSourcegetWebXmlSource(String filename, boolean global) Utility method to create an input source from the specified XML file.protected voidinit()Process a "init" event for this Context.voidlifecycleEvent(LifecycleEvent event) Process events for an associated Context.protected voidprocessAnnotations(Set<WebXml> fragments, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) protected voidprocessAnnotationsFile(File file, WebXml fragment, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) protected voidprocessAnnotationsInParallel(Set<WebXml> fragments, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) Parallelized version of processAnnotationsInParallel().protected voidprocessAnnotationsJar(URL url, WebXml fragment, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) protected voidprocessAnnotationsStream(InputStream is, WebXml fragment, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) protected String[]protected voidprocessAnnotationsUrl(URL url, WebXml fragment, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) protected voidprocessAnnotationsWebResource(WebResource webResource, WebXml fragment, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) protected voidprocessAnnotationWebFilter(String className, AnnotationEntry ae, WebXml fragment) process filter annotation and merge with existing one!protected voidprocessAnnotationWebServlet(String className, AnnotationEntry ae, WebXml fragment) protected voidprocessClass(WebXml fragment, JavaClass clazz) protected voidprocessClasses(WebXml webXml, Set<WebXml> orderedFragments) protected voidprocessContextConfig(Digester digester, URL contextXml, InputStream stream) Process a context.xml.processJarsForWebFragments(WebXml application, WebXmlParser webXmlParser) Scan /WEB-INF/lib for JARs and for each one found add it and any /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files will be parsed before being added to the map.protected voidprocessResourceJARs(Set<WebXml> fragments) Scan JARs that contain web-fragment.xml files that will be used to configure this application to see if they also contain static resources.protected voidScan JARs for ServletContainerInitializer implementations.voidsetCustomAuthenticators(Map<String, Authenticator> customAuthenticators) Sets custom mappings of login methods to authenticators.voidsetDefaultWebXml(String path) Set the location of the default deployment descriptor.protected voidValidate the usage of security role names in the web application deployment descriptor.protected voidScan the web.xml files that apply to the web application and merge them using the rules defined in the spec.
-
Field Details
-
sm
The string resources for this package. -
DUMMY_LOGIN_CONFIG
-
authenticators
The set of Authenticators that we know how to configure. The key is the name of the implemented authentication method, and the value is the fully qualified Java class name of the corresponding Valve. -
deploymentCount
protected static long deploymentCountDeployment count. -
hostWebXmlCache
protected static final Map<Host,org.apache.catalina.startup.ContextConfig.DefaultWebXmlCacheEntry> hostWebXmlCacheCache of default web.xml fragments per Host -
customAuthenticators
Custom mappings of login methods to authenticators -
context
The Context we are associated with. -
defaultWebXml
The default web application's deployment descriptor location. -
ok
protected boolean okTrack any fatal errors during startup configuration processing. -
originalDocBase
Original docBase. -
initializerClassMap
Map of ServletContainerInitializer to classes they expressed interest in. -
typeInitializerMap
Map of Types to ServletContainerInitializer that are interested in those types. -
handlesTypesAnnotations
protected boolean handlesTypesAnnotationsFlag that indicates if at least oneHandlesTypesentry is present that represents an annotation. -
handlesTypesNonAnnotations
protected boolean handlesTypesNonAnnotationsFlag that indicates if at least oneHandlesTypesentry is present that represents a non-annotation.
-
-
Constructor Details
-
ContextConfig
public ContextConfig()
-
-
Method Details
-
getDefaultWebXml
Obtain the location of the default deployment descriptor.- Returns:
- The path to the default web.xml. If not absolute, it is relative to CATALINA_BASE.
-
setDefaultWebXml
Set the location of the default deployment descriptor.- Parameters:
path- The path to the default web.xml. If not absolute, it is relative to CATALINA_BASE.
-
setCustomAuthenticators
Sets custom mappings of login methods to authenticators.- Parameters:
customAuthenticators- Custom mappings of login methods to authenticators
-
lifecycleEvent
Process events for an associated Context.- Specified by:
lifecycleEventin interfaceLifecycleListener- Parameters:
event- The lifecycle event that has occurred
-
applicationAnnotationsConfig
protected void applicationAnnotationsConfig()Process the application classes annotations, if it exists. -
authenticatorConfig
protected void authenticatorConfig()Set up an Authenticator automatically if required, and one has not already been configured. -
createContextDigester
Create (if necessary) and return a Digester configured to process the context configuration descriptor for an application.- Returns:
- the digester for context.xml files
-
getGenerateCode
protected boolean getGenerateCode() -
getUseGeneratedCode
protected boolean getUseGeneratedCode() -
getGeneratedCodeLocation
-
getGeneratedCodePackage
-
getContextXmlPackageName
-
getContextXmlJavaSource
-
generateClassHeader
-
contextConfig
Process the default configuration file, if it exists.- Parameters:
digester- The digester that will be used for XML parsing
-
processContextConfig
Process a context.xml.- Parameters:
digester- The digester that will be used for XML parsingcontextXml- The URL to the context.xml configurationstream- The XML resource stream
-
fixDocBase
Adjust docBase.- Throws:
IOException- cannot access the context base path
-
antiLocking
protected void antiLocking() -
init
protected void init()Process a "init" event for this Context. -
beforeStart
protected void beforeStart()Process a "before start" event for this Context. -
configureStart
protected void configureStart()Process a "contextConfig" event for this Context. -
configureStop
protected void configureStop()Process a "stop" event for this Context. -
destroy
protected void destroy()Process a "destroy" event for this Context. -
validateSecurityRoles
protected void validateSecurityRoles()Validate the usage of security role names in the web application deployment descriptor. If any problems are found, issue warning messages (for backwards compatibility) and add the missing roles. (To make these problems fatal instead, simply set theokinstance variable tofalseas well). -
getHostConfigBase
-
webConfig
protected void webConfig()Scan the web.xml files that apply to the web application and merge them using the rules defined in the spec. For the global web.xml files, where there is duplicate configuration, the most specific level wins. ie an application's web.xml takes precedence over the host level or global web.xml file. -
processClasses
-
createWebXml
-
processServletContainerInitializers
protected void processServletContainerInitializers()Scan JARs for ServletContainerInitializer implementations. -
processResourceJARs
Scan JARs that contain web-fragment.xml files that will be used to configure this application to see if they also contain static resources. If static resources are found, add them to the context. Resources are added in web-fragment.xml priority order.- Parameters:
fragments- The set of fragments that will be scanned for static resources
-
getGlobalWebXmlSource
Identify the default web.xml to be used and obtain an input source for it.- Returns:
- an input source to the default web.xml
-
getHostWebXmlSource
Identify the host web.xml to be used and obtain an input source for it.- Returns:
- an input source to the default per host web.xml
-
getContextWebXmlSource
Identify the application web.xml to be used and obtain an input source for it.- Returns:
- an input source to the context web.xml
-
getConfigBasePath
-
getWebXmlSource
Utility method to create an input source from the specified XML file.- Parameters:
filename- Name of the file (possibly with one or more leading path segments) to readglobal- true if processing a shared resource, false if processing a host based resource- Returns:
- the input source
-
processJarsForWebFragments
protected Map<String,WebXml> processJarsForWebFragments(WebXml application, WebXmlParser webXmlParser) Scan /WEB-INF/lib for JARs and for each one found add it and any /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files will be parsed before being added to the map. Every JAR will be added andnullwill be used if no web-fragment.xml was found. Any JARs known not contain fragments will be skipped.- Parameters:
application- The main web.xml metadatawebXmlParser- The parser to use to process the web.xml file- Returns:
- A map of JAR name to processed web fragment (if any)
-
processAnnotations
-
processAnnotationsInParallel
protected void processAnnotationsInParallel(Set<WebXml> fragments, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) Parallelized version of processAnnotationsInParallel(). Constructs tasks, submits them as they're created, then waits for completion.- Parameters:
fragments- Set of parallelizable scanshandlesTypesOnly- Important parameter for the underlying scanjavaClassCache- The class cache
-
processAnnotationsWebResource
protected void processAnnotationsWebResource(WebResource webResource, WebXml fragment, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) -
processAnnotationsUrl
-
processAnnotationsJar
-
processAnnotationsFile
-
processAnnotationsStream
protected void processAnnotationsStream(InputStream is, WebXml fragment, boolean handlesTypesOnly, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) throws ClassFormatException, IOException- Throws:
ClassFormatExceptionIOException
-
processClass
-
checkHandlesTypes
protected void checkHandlesTypes(JavaClass javaClass, Map<String, org.apache.catalina.startup.ContextConfig.JavaClassCacheEntry> javaClassCache) For classes packaged with the web application, the class and each super class needs to be checked for a match withHandlesTypesor for an annotation that matchesHandlesTypes.- Parameters:
javaClass- the class to checkjavaClassCache- a class cache
-
processAnnotationWebServlet
-
processAnnotationWebFilter
process filter annotation and merge with existing one! FIXME: refactoring method too long and has redundant subroutines with processAnnotationWebServlet!- Parameters:
className- The filter class nameae- The filter annotationfragment- The corresponding fragment
-
processAnnotationsStringArray
-
processAnnotationWebInitParams
-