Interface Context

All Superinterfaces:
Container, ContextBind, Lifecycle
All Known Implementing Classes:
FailedContext, ReplicatedContext, StandardContext

public interface Context extends Container, ContextBind
A Context is a Container that represents a servlet context, and therefore an individual web application, in the Catalina servlet engine. It is therefore useful in almost every deployment of Catalina (even if a Connector attached to a web server (such as Apache) uses the web server's facilities to identify the appropriate Wrapper to handle this request. It also provides a convenient mechanism to use Interceptors that see every request processed by this particular web application.

The parent Container attached to a Context is generally a Host, but may be some other implementation, or may be omitted if it is not necessary.

The child containers attached to a Context are generally implementations of Wrapper (representing individual servlet definitions).

Author:
Craig R. McClanahan
  • Field Details

    • ADD_WELCOME_FILE_EVENT

      static final String ADD_WELCOME_FILE_EVENT
      Container event for adding a welcome file.
      See Also:
    • REMOVE_WELCOME_FILE_EVENT

      static final String REMOVE_WELCOME_FILE_EVENT
      Container event for removing a wrapper.
      See Also:
    • CLEAR_WELCOME_FILES_EVENT

      static final String CLEAR_WELCOME_FILES_EVENT
      Container event for clearing welcome files.
      See Also:
    • CHANGE_SESSION_ID_EVENT

      static final String CHANGE_SESSION_ID_EVENT
      Container event for changing the ID of a session.
      See Also:
    • WEBAPP_PROTOCOL

      static final String WEBAPP_PROTOCOL
      Prefix for resource lookup.
      See Also:
  • Method Details

    • getAllowCasualMultipartParsing

      boolean getAllowCasualMultipartParsing()
      Returns true if requests mapped to servlets without "multipart config" to parse multipart/form-data requests anyway.
      Returns:
      true if requests mapped to servlets without "multipart config" to parse multipart/form-data requests, false otherwise.
    • setAllowCasualMultipartParsing

      void setAllowCasualMultipartParsing(boolean allowCasualMultipartParsing)
      Set to true to allow requests mapped to servlets that do not explicitly declare @MultipartConfig or have <multipart-config> specified in web.xml to parse multipart/form-data requests.
      Parameters:
      allowCasualMultipartParsing - true to allow such casual parsing, false otherwise.
    • getApplicationEventListeners

      Object[] getApplicationEventListeners()
      Obtain the registered application event listeners.
      Returns:
      An array containing the application event listener instances for this web application in the order they were specified in the web application deployment descriptor
    • setApplicationEventListeners

      void setApplicationEventListeners(Object[] listeners)
      Store the set of initialized application event listener objects, in the order they were specified in the web application deployment descriptor, for this application.
      Parameters:
      listeners - The set of instantiated listener objects.
    • getApplicationLifecycleListeners

      Object[] getApplicationLifecycleListeners()
      Obtain the registered application lifecycle listeners.
      Returns:
      An array containing the application lifecycle listener instances for this web application in the order they were specified in the web application deployment descriptor
    • setApplicationLifecycleListeners

      void setApplicationLifecycleListeners(Object[] listeners)
      Store the set of initialized application lifecycle listener objects, in the order they were specified in the web application deployment descriptor, for this application.
      Parameters:
      listeners - The set of instantiated listener objects.
    • getCharset

      String getCharset(Locale locale)
      Obtain the character set name to use with the given Locale. Note that different Contexts may have different mappings of Locale to character set.
      Parameters:
      locale - The locale for which the mapped character set should be returned
      Returns:
      The name of the character set to use with the given Locale
    • getConfigFile

      URL getConfigFile()
      Return the URL of the XML descriptor for this context.
      Returns:
      The URL of the XML descriptor for this context
    • setConfigFile

      void setConfigFile(URL configFile)
      Set the URL of the XML descriptor for this context.
      Parameters:
      configFile - The URL of the XML descriptor for this context.
    • getConfigured

      boolean getConfigured()
      Return the "correctly configured" flag for this Context.
      Returns:
      true if the Context has been correctly configured, otherwise false
    • setConfigured

      void setConfigured(boolean configured)
      Set the "correctly configured" flag for this Context. This can be set to false by startup listeners that detect a fatal configuration error to avoid the application from being made available.
      Parameters:
      configured - The new correctly configured flag
    • getCookies

      boolean getCookies()
      Return the "use cookies for session ids" flag.
      Returns:
      true if it is permitted to use cookies to track session IDs for this web application, otherwise false
    • setCookies

      void setCookies(boolean cookies)
      Set the "use cookies for session ids" flag.
      Parameters:
      cookies - The new flag
    • getSessionCookieName

      String getSessionCookieName()
      Gets the name to use for session cookies. Overrides any setting that may be specified by the application.
      Returns:
      The value of the default session cookie name or null if not specified
    • setSessionCookieName

      void setSessionCookieName(String sessionCookieName)
      Sets the name to use for session cookies. Overrides any setting that may be specified by the application.
      Parameters:
      sessionCookieName - The name to use
    • getUseHttpOnly

      boolean getUseHttpOnly()
      Gets the value of the use HttpOnly cookies for session cookies flag.
      Returns:
      true if the HttpOnly flag should be set on session cookies
    • setUseHttpOnly

      void setUseHttpOnly(boolean useHttpOnly)
      Sets the use HttpOnly cookies for session cookies flag.
      Parameters:
      useHttpOnly - Set to true to use HttpOnly cookies for session cookies
    • getUsePartitioned

      boolean getUsePartitioned()
      Should the Partitioned attribute be added to session cookies created for this web application.

      The name of the attribute used to indicate a partitioned cookie as part of CHIPS is not defined by an RFC and may change in a non-backwards compatible way once equivalent functionality is included in an RFC.

      Returns:
      true if the Partitioned attribute should be added to session cookies created for this web application, otherwise false
    • setUsePartitioned

      void setUsePartitioned(boolean usePartitioned)
      Configure whether the Partitioned attribute should be added to session cookies created for this web application.

      The name of the attribute used to indicate a partitioned cookie as part of CHIPS is not defined by an RFC and may change in a non-backwards compatible way once equivalent functionality is included in an RFC.

      Parameters:
      usePartitioned - true if the Partitioned attribute should be added to session cookies created for this web application, otherwise false
    • getSessionCookieDomain

      String getSessionCookieDomain()
      Gets the domain to use for session cookies. Overrides any setting that may be specified by the application.
      Returns:
      The value of the default session cookie domain or null if not specified
    • setSessionCookieDomain

      void setSessionCookieDomain(String sessionCookieDomain)
      Sets the domain to use for session cookies. Overrides any setting that may be specified by the application.
      Parameters:
      sessionCookieDomain - The domain to use
    • getSessionCookiePath

      String getSessionCookiePath()
      Gets the path to use for session cookies. Overrides any setting that may be specified by the application.
      Returns:
      The value of the default session cookie path or null if not specified
    • setSessionCookiePath

      void setSessionCookiePath(String sessionCookiePath)
      Sets the path to use for session cookies. Overrides any setting that may be specified by the application.
      Parameters:
      sessionCookiePath - The path to use
    • getSessionCookiePathUsesTrailingSlash

      boolean getSessionCookiePathUsesTrailingSlash()
      Is a / added to the end of the session cookie path to ensure browsers, particularly IE, don't send a session cookie for context /foo with requests intended for context /foobar.
      Returns:
      true if the slash is added, otherwise false
    • setSessionCookiePathUsesTrailingSlash

      void setSessionCookiePathUsesTrailingSlash(boolean sessionCookiePathUsesTrailingSlash)
      Configures if a / is added to the end of the session cookie path to ensure browsers, particularly IE, don't send a session cookie for context /foo with requests intended for context /foobar.
      Parameters:
      sessionCookiePathUsesTrailingSlash - true if the slash is should be added, otherwise false
    • getCrossContext

      boolean getCrossContext()
      Return the "allow crossing servlet contexts" flag.
      Returns:
      true if cross-contest requests are allowed from this web applications, otherwise false
    • getAltDDName

      String getAltDDName()
      Return the alternate Deployment Descriptor name.
      Returns:
      the name
    • setAltDDName

      void setAltDDName(String altDDName)
      Set an alternate Deployment Descriptor name.
      Parameters:
      altDDName - The new name
    • setCrossContext

      void setCrossContext(boolean crossContext)
      Set the "allow crossing servlet contexts" flag.
      Parameters:
      crossContext - The new cross contexts flag
    • getDenyUncoveredHttpMethods

      boolean getDenyUncoveredHttpMethods()
      Return the deny-uncovered-http-methods flag for this web application.
      Returns:
      The current value of the flag
    • setDenyUncoveredHttpMethods

      void setDenyUncoveredHttpMethods(boolean denyUncoveredHttpMethods)
      Set the deny-uncovered-http-methods flag for this web application.
      Parameters:
      denyUncoveredHttpMethods - The new deny-uncovered-http-methods flag
    • getDisplayName

      String getDisplayName()
      Return the display name of this web application.
      Returns:
      The display name
    • setDisplayName

      void setDisplayName(String displayName)
      Set the display name of this web application.
      Parameters:
      displayName - The new display name
    • getDistributable

      boolean getDistributable()
      Get the distributable flag for this web application.
      Returns:
      The value of the distributable flag for this web application.
    • setDistributable

      void setDistributable(boolean distributable)
      Set the distributable flag for this web application.
      Parameters:
      distributable - The new distributable flag
    • getDocBase

      String getDocBase()
      Obtain the document root for this Context.
      Returns:
      An absolute pathname or a relative (to the Host's appBase) pathname.
    • setDocBase

      void setDocBase(String docBase)
      Set the document root for this Context. This can be either an absolute pathname or a relative pathname. Relative pathnames are relative to the containing Host's appBase.
      Parameters:
      docBase - The new document root
    • getEncodedPath

      String getEncodedPath()
      Return the URL encoded context path
      Returns:
      The URL encoded (with UTF-8) context path
    • getIgnoreAnnotations

      boolean getIgnoreAnnotations()
      Determine if annotations parsing is currently disabled
      Returns:
      true if annotation parsing is disabled for this web application
    • setIgnoreAnnotations

      void setIgnoreAnnotations(boolean ignoreAnnotations)
      Set the boolean on the annotations parsing for this web application.
      Parameters:
      ignoreAnnotations - The boolean on the annotations parsing
    • getLoginConfig

      LoginConfig getLoginConfig()
      Returns:
      the login configuration descriptor for this web application.
    • setLoginConfig

      void setLoginConfig(LoginConfig config)
      Set the login configuration descriptor for this web application.
      Parameters:
      config - The new login configuration
    • getNamingResources

      NamingResourcesImpl getNamingResources()
      Returns:
      the naming resources associated with this web application.
    • setNamingResources

      void setNamingResources(NamingResourcesImpl namingResources)
      Set the naming resources for this web application.
      Parameters:
      namingResources - The new naming resources
    • getPath

      String getPath()
      Returns:
      the context path for this web application.
    • setPath

      void setPath(String path)
      Set the context path for this web application.
      Parameters:
      path - The new context path
    • getPublicId

      String getPublicId()
      Returns:
      the public identifier of the deployment descriptor DTD that is currently being parsed.
    • setPublicId

      void setPublicId(String publicId)
      Set the public identifier of the deployment descriptor DTD that is currently being parsed.
      Parameters:
      publicId - The public identifier
    • getReloadable

      boolean getReloadable()
      Returns:
      the reloadable flag for this web application.
    • setReloadable

      void setReloadable(boolean reloadable)
      Set the reloadable flag for this web application.
      Parameters:
      reloadable - The new reloadable flag
    • getOverride

      boolean getOverride()
      Returns:
      the override flag for this web application.
    • setOverride

      void setOverride(boolean override)
      Set the override flag for this web application.
      Parameters:
      override - The new override flag
    • getPrivileged

      boolean getPrivileged()
      Returns:
      the privileged flag for this web application.
    • setPrivileged

      void setPrivileged(boolean privileged)
      Set the privileged flag for this web application.
      Parameters:
      privileged - The new privileged flag
    • getServletContext

      ServletContext getServletContext()
      Returns:
      the Servlet context for which this Context is a facade.
    • getSessionTimeout

      int getSessionTimeout()
      Returns:
      the default session timeout (in minutes) for this web application.
    • setSessionTimeout

      void setSessionTimeout(int timeout)
      Set the default session timeout (in minutes) for this web application.
      Parameters:
      timeout - The new default session timeout
    • getSwallowAbortedUploads

      boolean getSwallowAbortedUploads()
      Returns true if remaining request data will be read (swallowed) even the request violates a data size constraint.
      Returns:
      true if data will be swallowed (default), false otherwise.
    • setSwallowAbortedUploads

      void setSwallowAbortedUploads(boolean swallowAbortedUploads)
      Set to false to disable request data swallowing after an upload was aborted due to size constraints.
      Parameters:
      swallowAbortedUploads - false to disable swallowing, true otherwise (default).
    • getSwallowOutput

      boolean getSwallowOutput()
      Returns:
      the value of the swallowOutput flag.
    • setSwallowOutput

      void setSwallowOutput(boolean swallowOutput)
      Set the value of the swallowOutput flag. If set to true, the system.out and system.err will be redirected to the logger during a servlet execution.
      Parameters:
      swallowOutput - The new value
    • getWrapperClass

      String getWrapperClass()
      Returns:
      the Java class name of the Wrapper implementation used for servlets registered in this Context.
    • setWrapperClass

      void setWrapperClass(String wrapperClass)
      Set the Java class name of the Wrapper implementation used for servlets registered in this Context.
      Parameters:
      wrapperClass - The new wrapper class
    • getXmlNamespaceAware

      boolean getXmlNamespaceAware()
      Will the parsing of web.xml and web-fragment.xml files for this Context be performed by a namespace aware parser?
      Returns:
      true if namespace awareness is enabled.
    • setXmlNamespaceAware

      void setXmlNamespaceAware(boolean xmlNamespaceAware)
      Controls whether the parsing of web.xml and web-fragment.xml files for this Context will be performed by a namespace aware parser.
      Parameters:
      xmlNamespaceAware - true to enable namespace awareness
    • getXmlValidation

      boolean getXmlValidation()
      Will the parsing of web.xml and web-fragment.xml files for this Context be performed by a validating parser?
      Returns:
      true if validation is enabled.
    • setXmlValidation

      void setXmlValidation(boolean xmlValidation)
      Controls whether the parsing of web.xml and web-fragment.xml files for this Context will be performed by a validating parser.
      Parameters:
      xmlValidation - true to enable xml validation
    • getXmlBlockExternal

      boolean getXmlBlockExternal()
      Will the parsing of web.xml, web-fragment.xml, *.tld, *.jspx, *.tagx and tagplugin.xml files for this Context block the use of external entities?
      Returns:
      true if access to external entities is blocked
    • setXmlBlockExternal

      void setXmlBlockExternal(boolean xmlBlockExternal)
      Controls whether the parsing of web.xml, web-fragment.xml, *.tld, *.jspx, *.tagx and tagplugin.xml files for this Context will block the use of external entities.
      Parameters:
      xmlBlockExternal - true to block external entities
    • getTldValidation

      boolean getTldValidation()
      Will the parsing of *.tld files for this Context be performed by a validating parser?
      Returns:
      true if validation is enabled.
    • setTldValidation

      void setTldValidation(boolean tldValidation)
      Controls whether the parsing of *.tld files for this Context will be performed by a validating parser.
      Parameters:
      tldValidation - true to enable xml validation
    • getJarScanner

      JarScanner getJarScanner()
      Get the Jar Scanner to be used to scan for JAR resources for this context.
      Returns:
      The Jar Scanner configured for this context.
    • setJarScanner

      void setJarScanner(JarScanner jarScanner)
      Set the Jar Scanner to be used to scan for JAR resources for this context.
      Parameters:
      jarScanner - The Jar Scanner to be used for this context.
    • getAuthenticator

      Authenticator getAuthenticator()
      Returns:
      the Authenticator that is used by this context. This is always non-null for a started Context
    • setLogEffectiveWebXml

      void setLogEffectiveWebXml(boolean logEffectiveWebXml)
      Set whether or not the effective web.xml for this context should be logged on context start.
      Parameters:
      logEffectiveWebXml - set to true to log the complete web.xml that will be used for the webapp
    • getLogEffectiveWebXml

      boolean getLogEffectiveWebXml()
      Should the effective web.xml for this context be logged on context start?
      Returns:
      true if the reconstructed web.xml that will be used for the webapp should be logged
    • getInstanceManager

      InstanceManager getInstanceManager()
      Returns:
      the instance manager associated with this context.
    • setInstanceManager

      void setInstanceManager(InstanceManager instanceManager)
      Set the instance manager associated with this context.
      Parameters:
      instanceManager - the new instance manager instance
    • setContainerSciFilter

      void setContainerSciFilter(String containerSciFilter)
      Sets the regular expression that specifies which container provided SCIs should be filtered out and not used for this context. Matching uses Matcher.find() so the regular expression only has to match a sub-string of the fully qualified class name of the container provided SCI for it to be filtered out.
      Parameters:
      containerSciFilter - The regular expression against which the fully qualified class name of each container provided SCI should be checked
    • getContainerSciFilter

      String getContainerSciFilter()
      Obtains the regular expression that specifies which container provided SCIs should be filtered out and not used for this context. Matching uses Matcher.find() so the regular expression only has to match a sub-string of the fully qualified class name of the container provided SCI for it to be filtered out.
      Returns:
      The regular expression against which the fully qualified class name of each container provided SCI will be checked
    • isParallelAnnotationScanning

      @Deprecated default boolean isParallelAnnotationScanning()
      Deprecated.
      This method will be removed in Tomcat 11 onwards
      Returns:
      the value of the parallel annotation scanning flag. If true, it will dispatch scanning to the utility executor.
    • getParallelAnnotationScanning

      boolean getParallelAnnotationScanning()
      Returns:
      the value of the parallel annotation scanning flag. If true, it will dispatch scanning to the utility executor.
    • setParallelAnnotationScanning

      void setParallelAnnotationScanning(boolean parallelAnnotationScanning)
      Set the parallel annotation scanning value.
      Parameters:
      parallelAnnotationScanning - new parallel annotation scanning flag
    • addApplicationListener

      void addApplicationListener(String listener)
      Add a new Listener class name to the set of Listeners configured for this application.
      Parameters:
      listener - Java class name of a listener class
    • addApplicationParameter

      void addApplicationParameter(ApplicationParameter parameter)
      Add a new application parameter for this application.
      Parameters:
      parameter - The new application parameter
    • addConstraint

      void addConstraint(SecurityConstraint constraint)
      Add a security constraint to the set for this web application.
      Parameters:
      constraint - The security constraint that should be added
    • addErrorPage

      void addErrorPage(ErrorPage errorPage)
      Add an error page for the specified error or Java exception.
      Parameters:
      errorPage - The error page definition to be added
    • addFilterDef

      void addFilterDef(FilterDef filterDef)
      Add a filter definition to this Context.
      Parameters:
      filterDef - The filter definition to be added
    • addFilterMap

      void addFilterMap(FilterMap filterMap)
      Add a filter mapping to this Context.
      Parameters:
      filterMap - The filter mapping to be added
    • addFilterMapBefore

      void addFilterMapBefore(FilterMap filterMap)
      Add a filter mapping to this Context before the mappings defined in the deployment descriptor but after any other mappings added via this method.
      Parameters:
      filterMap - The filter mapping to be added
      Throws:
      IllegalArgumentException - if the specified filter name does not match an existing filter definition, or the filter mapping is malformed
    • addLocaleEncodingMappingParameter

      void addLocaleEncodingMappingParameter(String locale, String encoding)
      Add a Locale Encoding Mapping (see Sec 5.4 of Servlet spec 2.4)
      Parameters:
      locale - locale to map an encoding for
      encoding - encoding to be used for a give locale
    • addMimeMapping

      void addMimeMapping(String extension, String mimeType)
      Add a new MIME mapping, replacing any existing mapping for the specified extension.
      Parameters:
      extension - Filename extension being mapped
      mimeType - Corresponding MIME type
    • addParameter

      void addParameter(String name, String value)
      Add a new context initialization parameter, replacing any existing value for the specified name.
      Parameters:
      name - Name of the new parameter
      value - Value of the new parameter
    • addRoleMapping

      void addRoleMapping(String role, String link)
      Add a security role reference for this web application.
      Parameters:
      role - Security role used in the application
      link - Actual security role to check for
    • addSecurityRole

      void addSecurityRole(String role)
      Add a new security role for this web application.
      Parameters:
      role - New security role
    • addServletMappingDecoded

      default void addServletMappingDecoded(String pattern, String name)
      Add a new servlet mapping, replacing any existing mapping for the specified pattern.
      Parameters:
      pattern - URL pattern to be mapped
      name - Name of the corresponding servlet to execute
    • addServletMappingDecoded

      void addServletMappingDecoded(String pattern, String name, boolean jspWildcard)
      Add a new servlet mapping, replacing any existing mapping for the specified pattern.
      Parameters:
      pattern - URL pattern to be mapped
      name - Name of the corresponding servlet to execute
      jspWildcard - true if name identifies the JspServlet and pattern contains a wildcard; false otherwise
    • addWatchedResource

      void addWatchedResource(String name)
      Add a resource which will be watched for reloading by the host auto deployer. Note: this will not be used in embedded mode.
      Parameters:
      name - Path to the resource, relative to docBase
    • addWelcomeFile

      void addWelcomeFile(String name)
      Add a new welcome file to the set recognized by this Context.
      Parameters:
      name - New welcome file name
    • addWrapperLifecycle

      void addWrapperLifecycle(String listener)
      Add the classname of a LifecycleListener to be added to each Wrapper appended to this Context.
      Parameters:
      listener - Java class name of a LifecycleListener class
    • addWrapperListener

      void addWrapperListener(String listener)
      Add the classname of a ContainerListener to be added to each Wrapper appended to this Context.
      Parameters:
      listener - Java class name of a ContainerListener class
    • createInstanceManager

      InstanceManager createInstanceManager()
      Factory method to create and return a new InstanceManager instance. This can be used for framework integration or easier configuration with custom Context implementations.
      Returns:
      the instance manager
    • createWrapper

      Wrapper createWrapper()
      Factory method to create and return a new Wrapper instance, of the Java implementation class appropriate for this Context implementation. The constructor of the instantiated Wrapper will have been called, but no properties will have been set.
      Returns:
      a newly created wrapper instance that is used to wrap a Servlet
    • findApplicationListeners

      String[] findApplicationListeners()
      Returns:
      the set of application listener class names configured for this application.
    • findApplicationParameters

      ApplicationParameter[] findApplicationParameters()
      Returns:
      the set of application parameters for this application.
    • findConstraints

      SecurityConstraint[] findConstraints()
      Returns:
      the set of security constraints for this web application. If there are none, a zero-length array is returned.
    • findErrorPage

      ErrorPage findErrorPage(int errorCode)
      Parameters:
      errorCode - Error code to look up
      Returns:
      the error page entry for the specified HTTP error code, if any; otherwise return null.
    • findErrorPage

      ErrorPage findErrorPage(Throwable throwable)
      Find and return the ErrorPage instance for the specified exception's class, or an ErrorPage instance for the closest superclass for which there is such a definition. If no associated ErrorPage instance is found, return null.
      Parameters:
      throwable - The exception type for which to find an ErrorPage
      Returns:
      the error page entry for the specified Java exception type, if any; otherwise return null.
    • findErrorPages

      ErrorPage[] findErrorPages()
      Returns:
      the set of defined error pages for all specified error codes and exception types.
    • findFilterDef

      FilterDef findFilterDef(String filterName)
      Parameters:
      filterName - Filter name to look up
      Returns:
      the filter definition for the specified filter name, if any; otherwise return null.
    • findFilterDefs

      FilterDef[] findFilterDefs()
      Returns:
      the set of defined filters for this Context.
    • findFilterMaps

      FilterMap[] findFilterMaps()
      Returns:
      the set of filter mappings for this Context.
    • findMimeMapping

      String findMimeMapping(String extension)
      Parameters:
      extension - Extension to map to a MIME type
      Returns:
      the MIME type to which the specified extension is mapped, if any; otherwise return null.
    • findMimeMappings

      String[] findMimeMappings()
      Returns:
      the extensions for which MIME mappings are defined. If there are none, a zero-length array is returned.
    • findParameter

      String findParameter(String name)
      Parameters:
      name - Name of the parameter to return
      Returns:
      the value for the specified context initialization parameter name, if any; otherwise return null.
    • findParameters

      String[] findParameters()
      Returns:
      the names of all defined context initialization parameters for this Context. If no parameters are defined, a zero-length array is returned.
    • findRoleMapping

      String findRoleMapping(String role)
      For the given security role (as used by an application), return the corresponding role name (as defined by the underlying Realm) if there is one. Otherwise, return the specified role unchanged.
      Parameters:
      role - Security role to map
      Returns:
      The role name that was mapped to the specified role
    • findSecurityRole

      boolean findSecurityRole(String role)
      Parameters:
      role - Security role to verify
      Returns:
      true if the specified security role is defined for this application; otherwise return false.
    • findSecurityRoles

      String[] findSecurityRoles()
      Returns:
      the security roles defined for this application. If none have been defined, a zero-length array is returned.
    • findServletMapping

      String findServletMapping(String pattern)
      Parameters:
      pattern - Pattern for which a mapping is requested
      Returns:
      the servlet name mapped by the specified pattern (if any); otherwise return null.
    • findServletMappings

      String[] findServletMappings()
      Returns:
      the patterns of all defined servlet mappings for this Context. If no mappings are defined, a zero-length array is returned.
    • getThreadBindingListener

      ThreadBindingListener getThreadBindingListener()
      Returns:
      the associated ThreadBindingListener.
    • setThreadBindingListener

      void setThreadBindingListener(ThreadBindingListener threadBindingListener)
      Get the associated ThreadBindingListener.
      Parameters:
      threadBindingListener - Set the listener that will receive notifications when entering and exiting the application scope
    • findWatchedResources

      String[] findWatchedResources()
      Returns:
      the set of watched resources for this Context. If none are defined, a zero length array will be returned.
    • findWelcomeFile

      boolean findWelcomeFile(String name)
      Parameters:
      name - Welcome file to verify
      Returns:
      true if the specified welcome file is defined for this Context; otherwise return false.
    • findWelcomeFiles

      String[] findWelcomeFiles()
      Returns:
      the set of welcome files defined for this Context. If none are defined, a zero-length array is returned.
    • findWrapperLifecycles

      String[] findWrapperLifecycles()
      Returns:
      the set of LifecycleListener classes that will be added to newly created Wrappers automatically.
    • findWrapperListeners

      String[] findWrapperListeners()
      Returns:
      the set of ContainerListener classes that will be added to newly created Wrappers automatically.
    • fireRequestInitEvent

      boolean fireRequestInitEvent(ServletRequest request)
      Notify all ServletRequestListeners that a request has started.
      Parameters:
      request - The request object that will be passed to the listener
      Returns:
      true if the listeners fire successfully, else false
    • fireRequestDestroyEvent

      boolean fireRequestDestroyEvent(ServletRequest request)
      Notify all ServletRequestListeners that a request has ended.
      Parameters:
      request - The request object that will be passed to the listener
      Returns:
      true if the listeners fire successfully, else false
    • reload

      void reload()
      Reload this web application, if reloading is supported.
      Throws:
      IllegalStateException - if the reloadable property is set to false.
    • removeApplicationListener

      void removeApplicationListener(String listener)
      Remove the specified application listener class from the set of listeners for this application.
      Parameters:
      listener - Java class name of the listener to be removed
    • removeApplicationParameter

      void removeApplicationParameter(String name)
      Remove the application parameter with the specified name from the set for this application.
      Parameters:
      name - Name of the application parameter to remove
    • removeConstraint

      void removeConstraint(SecurityConstraint constraint)
      Remove the specified security constraint from this web application.
      Parameters:
      constraint - Constraint to be removed
    • removeErrorPage

      void removeErrorPage(ErrorPage errorPage)
      Remove the error page for the specified error code or Java language exception, if it exists; otherwise, no action is taken.
      Parameters:
      errorPage - The error page definition to be removed
    • removeFilterDef

      void removeFilterDef(FilterDef filterDef)
      Remove the specified filter definition from this Context, if it exists; otherwise, no action is taken.
      Parameters:
      filterDef - Filter definition to be removed
    • removeFilterMap

      void removeFilterMap(FilterMap filterMap)
      Remove a filter mapping from this Context.
      Parameters:
      filterMap - The filter mapping to be removed
    • removeMimeMapping

      void removeMimeMapping(String extension)
      Remove the MIME mapping for the specified extension, if it exists; otherwise, no action is taken.
      Parameters:
      extension - Extension to remove the mapping for
    • removeParameter

      void removeParameter(String name)
      Remove the context initialization parameter with the specified name, if it exists; otherwise, no action is taken.
      Parameters:
      name - Name of the parameter to remove
    • removeRoleMapping

      void removeRoleMapping(String role)
      Remove any security role reference for the specified name
      Parameters:
      role - Security role (as used in the application) to remove
    • removeSecurityRole

      void removeSecurityRole(String role)
      Remove any security role with the specified name.
      Parameters:
      role - Security role to remove
    • removeServletMapping

      void removeServletMapping(String pattern)
      Remove any servlet mapping for the specified pattern, if it exists; otherwise, no action is taken.
      Parameters:
      pattern - URL pattern of the mapping to remove
    • removeWatchedResource

      void removeWatchedResource(String name)
      Remove the specified watched resource name from the list associated with this Context.
      Parameters:
      name - Name of the watched resource to be removed
    • removeWelcomeFile

      void removeWelcomeFile(String name)
      Remove the specified welcome file name from the list recognized by this Context.
      Parameters:
      name - Name of the welcome file to be removed
    • removeWrapperLifecycle

      void removeWrapperLifecycle(String listener)
      Remove a class name from the set of LifecycleListener classes that will be added to newly created Wrappers.
      Parameters:
      listener - Class name of a LifecycleListener class to be removed
    • removeWrapperListener

      void removeWrapperListener(String listener)
      Remove a class name from the set of ContainerListener classes that will be added to newly created Wrappers.
      Parameters:
      listener - Class name of a ContainerListener class to be removed
    • getRealPath

      String getRealPath(String path)
      Parameters:
      path - The path to the desired resource
      Returns:
      the real path for a given virtual path, if possible; otherwise return null.
    • getEffectiveMajorVersion

      int getEffectiveMajorVersion()
      Returns:
      the effective major version of the Servlet spec used by this context.
    • setEffectiveMajorVersion

      void setEffectiveMajorVersion(int major)
      Set the effective major version of the Servlet spec used by this context.
      Parameters:
      major - Set the version number
    • getEffectiveMinorVersion

      int getEffectiveMinorVersion()
      Returns:
      the effective minor version of the Servlet spec used by this context.
    • setEffectiveMinorVersion

      void setEffectiveMinorVersion(int minor)
      Set the effective minor version of the Servlet spec used by this context.
      Parameters:
      minor - Set the version number
    • getJspConfigDescriptor

      JspConfigDescriptor getJspConfigDescriptor()
      Returns:
      the JSP configuration for this context. Will be null if there is no JSP configuration.
    • setJspConfigDescriptor

      void setJspConfigDescriptor(JspConfigDescriptor descriptor)
      Set the JspConfigDescriptor for this context. A null value indicates there is not JSP configuration.
      Parameters:
      descriptor - the new JSP configuration
    • addServletContainerInitializer

      void addServletContainerInitializer(ServletContainerInitializer sci, Set<Class<?>> classes)
      Add a ServletContainerInitializer instance to this web application.
      Parameters:
      sci - The instance to add
      classes - The classes in which the initializer expressed an interest
    • getPaused

      boolean getPaused()
      Is this Context paused whilst it is reloaded?
      Returns:
      true if the context has been paused
    • isServlet22

      boolean isServlet22()
      Is this context using version 2.2 of the Servlet spec?
      Returns:
      true for a legacy Servlet 2.2 webapp
    • addServletSecurity

      Set<String> addServletSecurity(ServletRegistration.Dynamic registration, ServletSecurityElement servletSecurityElement)
      Notification that Servlet security has been dynamically set in a ServletRegistration.Dynamic
      Parameters:
      registration - Servlet security was modified for
      servletSecurityElement - new security constraints for this Servlet
      Returns:
      urls currently mapped to this registration that are already present in web.xml
    • setResourceOnlyServlets

      void setResourceOnlyServlets(String resourceOnlyServlets)
      Sets the (comma separated) list of Servlets that expect a resource to be present. Used to ensure that welcome files associated with Servlets that expect a resource to be present are not mapped when there is no resource.
      Parameters:
      resourceOnlyServlets - The Servlet names comma separated list
    • getResourceOnlyServlets

      String getResourceOnlyServlets()
      Obtains the list of Servlets that expect a resource to be present.
      Returns:
      A comma separated list of Servlet names as used in web.xml
    • isResourceOnlyServlet

      boolean isResourceOnlyServlet(String servletName)
      Checks the named Servlet to see if it expects a resource to be present.
      Parameters:
      servletName - Name of the Servlet (as per web.xml) to check
      Returns:
      true if the Servlet expects a resource, otherwise false
    • getBaseName

      String getBaseName()
      Returns:
      the base name to use for WARs, directories or context.xml files for this context.
    • setWebappVersion

      void setWebappVersion(String webappVersion)
      Set the version of this web application - used to differentiate different versions of the same web application when using parallel deployment.
      Parameters:
      webappVersion - The webapp version associated with the context, which should be unique
    • getWebappVersion

      String getWebappVersion()
      Returns:
      The version of this web application, used to differentiate different versions of the same web application when using parallel deployment. If not specified, defaults to the empty string.
    • setFireRequestListenersOnForwards

      void setFireRequestListenersOnForwards(boolean enable)
      Configure whether or not requests listeners will be fired on forwards for this Context.
      Parameters:
      enable - true to fire request listeners when forwarding
    • getFireRequestListenersOnForwards

      boolean getFireRequestListenersOnForwards()
      Returns:
      whether or not requests listeners will be fired on forwards for this Context.
    • setPreemptiveAuthentication

      void setPreemptiveAuthentication(boolean enable)
      Configures if a user presents authentication credentials, whether the context will process them when the request is for a non-protected resource.
      Parameters:
      enable - true to perform authentication even outside security constraints
    • getPreemptiveAuthentication

      boolean getPreemptiveAuthentication()
      Returns:
      if a user presents authentication credentials, will the context will process them when the request is for a non-protected resource.
    • setSendRedirectBody

      void setSendRedirectBody(boolean enable)
      Configures if a response body is included when a redirect response is sent to the client.
      Parameters:
      enable - true to send a response body for redirects
    • getSendRedirectBody

      boolean getSendRedirectBody()
      Returns:
      if the context is configured to include a response body as part of a redirect response.
    • getLoader

      Loader getLoader()
      Returns:
      the Loader with which this Context is associated.
    • setLoader

      void setLoader(Loader loader)
      Set the Loader with which this Context is associated.
      Parameters:
      loader - The newly associated loader
    • getResources

      WebResourceRoot getResources()
      Returns:
      the Resources with which this Context is associated.
    • setResources

      void setResources(WebResourceRoot resources)
      Set the Resources object with which this Context is associated.
      Parameters:
      resources - The newly associated Resources
    • getManager

      Manager getManager()
      Returns:
      the Manager with which this Context is associated. If there is no associated Manager, return null.
    • setManager

      void setManager(Manager manager)
      Set the Manager with which this Context is associated.
      Parameters:
      manager - The newly associated Manager
    • setAddWebinfClassesResources

      void setAddWebinfClassesResources(boolean addWebinfClassesResources)
      Sets the flag that indicates if /WEB-INF/classes should be treated like an exploded JAR and JAR resources made available as if they were in a JAR.
      Parameters:
      addWebinfClassesResources - The new value for the flag
    • getAddWebinfClassesResources

      boolean getAddWebinfClassesResources()
      Returns:
      the flag that indicates if /WEB-INF/classes should be treated like an exploded JAR and JAR resources made available as if they were in a JAR.
    • addPostConstructMethod

      void addPostConstructMethod(String clazz, String method)
      Add a post construct method definition for the given class, if there is an existing definition for the specified class - IllegalArgumentException will be thrown.
      Parameters:
      clazz - Fully qualified class name
      method - Post construct method name
      Throws:
      IllegalArgumentException - if the fully qualified class name or method name are NULL; if there is already post construct method definition for the given class
    • addPreDestroyMethod

      void addPreDestroyMethod(String clazz, String method)
      Add a pre destroy method definition for the given class, if there is an existing definition for the specified class - IllegalArgumentException will be thrown.
      Parameters:
      clazz - Fully qualified class name
      method - Post construct method name
      Throws:
      IllegalArgumentException - if the fully qualified class name or method name are NULL; if there is already pre destroy method definition for the given class
    • removePostConstructMethod

      void removePostConstructMethod(String clazz)
      Removes the post construct method definition for the given class, if it exists; otherwise, no action is taken.
      Parameters:
      clazz - Fully qualified class name
    • removePreDestroyMethod

      void removePreDestroyMethod(String clazz)
      Removes the pre destroy method definition for the given class, if it exists; otherwise, no action is taken.
      Parameters:
      clazz - Fully qualified class name
    • findPostConstructMethod

      String findPostConstructMethod(String clazz)
      Returns the method name that is specified as post construct method for the given class, if it exists; otherwise NULL will be returned.
      Parameters:
      clazz - Fully qualified class name
      Returns:
      the method name that is specified as post construct method for the given class, if it exists; otherwise NULL will be returned.
    • findPreDestroyMethod

      String findPreDestroyMethod(String clazz)
      Returns the method name that is specified as pre destroy method for the given class, if it exists; otherwise NULL will be returned.
      Parameters:
      clazz - Fully qualified class name
      Returns:
      the method name that is specified as pre destroy method for the given class, if it exists; otherwise NULL will be returned.
    • findPostConstructMethods

      Map<String,String> findPostConstructMethods()
      Returns a map with keys - fully qualified class names of the classes that have post construct methods and the values are the corresponding method names. If there are no such classes an empty map will be returned.
      Returns:
      a map with keys - fully qualified class names of the classes that have post construct methods and the values are the corresponding method names.
    • findPreDestroyMethods

      Map<String,String> findPreDestroyMethods()
      Returns a map with keys - fully qualified class names of the classes that have pre destroy methods and the values are the corresponding method names. If there are no such classes an empty map will be returned.
      Returns:
      a map with keys - fully qualified class names of the classes that have pre destroy methods and the values are the corresponding method names.
    • getNamingToken

      Object getNamingToken()
      Returns:
      the token necessary for operations on the associated JNDI naming context.
    • setCookieProcessor

      void setCookieProcessor(CookieProcessor cookieProcessor)
      Sets the CookieProcessor that will be used to process cookies for this Context.
      Parameters:
      cookieProcessor - The new cookie processor
      Throws:
      IllegalArgumentException - If a null CookieProcessor is specified
    • getCookieProcessor

      CookieProcessor getCookieProcessor()
      Returns:
      the CookieProcessor that will be used to process cookies for this Context.
    • setValidateClientProvidedNewSessionId

      void setValidateClientProvidedNewSessionId(boolean validateClientProvidedNewSessionId)
      When a client provides the ID for a new session, should that ID be validated? The only use case for using a client provided session ID is to have a common session ID across multiple web applications. Therefore, any client provided session ID should already exist in another web application. If this check is enabled, the client provided session ID will only be used if the session ID exists in at least one other web application for the current host. Note that the following additional tests are always applied, irrespective of this setting:
      • The session ID is provided by a cookie
      • The session cookie has a path of /
      Parameters:
      validateClientProvidedNewSessionId - true if validation should be applied
    • getValidateClientProvidedNewSessionId

      boolean getValidateClientProvidedNewSessionId()
      Will client provided session IDs be validated (see setValidateClientProvidedNewSessionId(boolean)) before use?
      Returns:
      true if validation will be applied. Otherwise, false
    • setMapperContextRootRedirectEnabled

      void setMapperContextRootRedirectEnabled(boolean mapperContextRootRedirectEnabled)
      If enabled, requests for a web application context root will be redirected (adding a trailing slash) by the Mapper. This is more efficient but has the side effect of confirming that the context path is valid.
      Parameters:
      mapperContextRootRedirectEnabled - Should the redirects be enabled?
    • getMapperContextRootRedirectEnabled

      boolean getMapperContextRootRedirectEnabled()
      Determines if requests for a web application context root will be redirected (adding a trailing slash) by the Mapper. This is more efficient but has the side effect of confirming that the context path is valid.
      Returns:
      true if the Mapper level redirect is enabled for this Context.
    • setMapperDirectoryRedirectEnabled

      void setMapperDirectoryRedirectEnabled(boolean mapperDirectoryRedirectEnabled)
      If enabled, requests for a directory will be redirected (adding a trailing slash) by the Mapper. This is more efficient but has the side effect of confirming that the directory is valid.
      Parameters:
      mapperDirectoryRedirectEnabled - Should the redirects be enabled?
    • getMapperDirectoryRedirectEnabled

      boolean getMapperDirectoryRedirectEnabled()
      Determines if requests for a directory will be redirected (adding a trailing slash) by the Mapper. This is more efficient but has the side effect of confirming that the directory is valid.
      Returns:
      true if the Mapper level redirect is enabled for this Context.
    • setUseRelativeRedirects

      void setUseRelativeRedirects(boolean useRelativeRedirects)
      Controls whether HTTP 1.1 and later location headers generated by a call to HttpServletResponse.sendRedirect(String) will use relative or absolute redirects.

      Relative redirects are more efficient but may not work with reverse proxies that change the context path. It should be noted that it is not recommended to use a reverse proxy to change the context path because of the multiple issues it creates.

      Absolute redirects should work with reverse proxies that change the context path but may cause issues with the RemoteIpFilter if the filter is changing the scheme and/or port.

      Parameters:
      useRelativeRedirects - true to use relative redirects and false to use absolute redirects
    • getUseRelativeRedirects

      boolean getUseRelativeRedirects()
      Will HTTP 1.1 and later location headers generated by a call to HttpServletResponse.sendRedirect(String) use relative or absolute redirects.
      Returns:
      true if relative redirects will be used false if absolute redirects are used.
      See Also:
    • setDispatchersUseEncodedPaths

      void setDispatchersUseEncodedPaths(boolean dispatchersUseEncodedPaths)
      Are paths used in calls to obtain a request dispatcher expected to be encoded? This affects both how Tomcat handles calls to obtain a request dispatcher as well as how Tomcat generates paths used to obtain request dispatchers internally.
      Parameters:
      dispatchersUseEncodedPaths - true to use encoded paths, otherwise false
    • getDispatchersUseEncodedPaths

      boolean getDispatchersUseEncodedPaths()
      Are paths used in calls to obtain a request dispatcher expected to be encoded? This applies to both how Tomcat handles calls to obtain a request dispatcher as well as how Tomcat generates paths used to obtain request dispatchers internally.
      Returns:
      true if encoded paths will be used, otherwise false
    • setRequestCharacterEncoding

      void setRequestCharacterEncoding(String encoding)
      Set the default request body encoding for this web application.
      Parameters:
      encoding - The default encoding
    • getRequestCharacterEncoding

      String getRequestCharacterEncoding()
      Get the default request body encoding for this web application.
      Returns:
      The default request body encoding
    • setResponseCharacterEncoding

      void setResponseCharacterEncoding(String encoding)
      Set the default response body encoding for this web application.
      Parameters:
      encoding - The default encoding
    • getResponseCharacterEncoding

      String getResponseCharacterEncoding()
      Get the default response body encoding for this web application.
      Returns:
      The default response body encoding
    • setAllowMultipleLeadingForwardSlashInPath

      void setAllowMultipleLeadingForwardSlashInPath(boolean allowMultipleLeadingForwardSlashInPath)
      Configure if, when returning a context path from HttpServletRequest.getContextPath(), the return value is allowed to contain multiple leading '/' characters.
      Parameters:
      allowMultipleLeadingForwardSlashInPath - The new value for the flag
    • getAllowMultipleLeadingForwardSlashInPath

      boolean getAllowMultipleLeadingForwardSlashInPath()
      When returning a context path from HttpServletRequest.getContextPath(), is it allowed to contain multiple leading '/' characters?
      Returns:
      true if multiple leading '/' characters are allowed, otherwise false
    • incrementInProgressAsyncCount

      void incrementInProgressAsyncCount()
    • decrementInProgressAsyncCount

      void decrementInProgressAsyncCount()
    • setCreateUploadTargets

      void setCreateUploadTargets(boolean createUploadTargets)
      Configure whether Tomcat will attempt to create an upload target used by this web application if it does not exist when the web application attempts to use it.
      Parameters:
      createUploadTargets - true if Tomcat should attempt to create the upload target, otherwise false
    • getCreateUploadTargets

      boolean getCreateUploadTargets()
      Will Tomcat attempt to create an upload target used by this web application if it does not exist when the web application attempts to use it?
      Returns:
      true if Tomcat will attempt to create an upload target otherwise false
    • getAlwaysAccessSession

      boolean getAlwaysAccessSession()
      If this is true, every request that is associated with a session will cause the session's last accessed time to be updated regardless of whether or not the request explicitly accesses the session. If org.apache.catalina.STRICT_SERVLET_COMPLIANCE is set to true, the default of this setting will be true, else the default value will be false.
      Returns:
      the flag value
    • setAlwaysAccessSession

      void setAlwaysAccessSession(boolean alwaysAccessSession)
      Set the session access behavior.
      Parameters:
      alwaysAccessSession - the new flag value
    • getContextGetResourceRequiresSlash

      boolean getContextGetResourceRequiresSlash()
      If this is true then the path passed to ServletContext.getResource() or ServletContext.getResourceAsStream() must start with "/". If false, code like getResource("myfolder/myresource.txt") will work as Tomcat will prepend "/" to the provided path. If org.apache.catalina.STRICT_SERVLET_COMPLIANCE is set to true, the default of this setting will be true, else the default value will be false.
      Returns:
      the flag value
    • setContextGetResourceRequiresSlash

      void setContextGetResourceRequiresSlash(boolean contextGetResourceRequiresSlash)
      Allow using ServletContext.getResource() or ServletContext.getResourceAsStream() without a leading "/".
      Parameters:
      contextGetResourceRequiresSlash - the new flag value
    • getDispatcherWrapsSameObject

      boolean getDispatcherWrapsSameObject()
      If this is true then any wrapped request or response object passed to an application dispatcher will be checked to ensure that it has wrapped the original request or response. If org.apache.catalina.STRICT_SERVLET_COMPLIANCE is set to true, the default of this setting will be true, else the default value will be false.
      Returns:
      the flag value
    • setDispatcherWrapsSameObject

      void setDispatcherWrapsSameObject(boolean dispatcherWrapsSameObject)
      Allow disabling the object wrap check in the request dispatcher.
      Parameters:
      dispatcherWrapsSameObject - the new flag value
    • getSuspendWrappedResponseAfterForward

      boolean getSuspendWrappedResponseAfterForward()
      If this is true, then following a forward the response will be unwrapped to suspend the Catalina response instead of simply closing the top level response. The default value is false.
      Returns:
      the flag value
    • setSuspendWrappedResponseAfterForward

      void setSuspendWrappedResponseAfterForward(boolean suspendWrappedResponseAfterForward)
      Allows unwrapping the response object to suspend the response following a forward.
      Parameters:
      suspendWrappedResponseAfterForward - the new flag value
    • findConfigFileResource

      default ConfigurationSource.Resource findConfigFileResource(String name) throws IOException
      Find configuration file with the specified path, first looking into the webapp resources, then delegating to ConfigFileLoader.getSource().getResource. The WEBAPP_PROTOCOL constant prefix is used to denote webapp resources.
      Parameters:
      name - The resource name
      Returns:
      the resource
      Throws:
      IOException - if an error occurs or if the resource does not exist
    • getUseBloomFilterForArchives

      @Deprecated boolean getUseBloomFilterForArchives()
      Deprecated.
      This method will be removed in Tomcat 11 onwards. Use WebResourceRoot.getArchiveIndexStrategy()
      Returns:
      true if the resources archive lookup will use a bloom filter.
    • setUseBloomFilterForArchives

      @Deprecated void setUseBloomFilterForArchives(boolean useBloomFilterForArchives)
      Deprecated.
      This method will be removed in Tomcat 11 onwards Use WebResourceRoot.setArchiveIndexStrategy(String)
      Set bloom filter flag value.
      Parameters:
      useBloomFilterForArchives - The new fast class path scan flag