Class ContextHandler

    • Field Detail

      • SERVLET_LISTENER_TYPES

        public static final java.lang.Class<?>[] SERVLET_LISTENER_TYPES
      • DEFAULT_LISTENER_TYPE_INDEX

        public static final int DEFAULT_LISTENER_TYPE_INDEX
        See Also:
        Constant Field Values
      • EXTENDED_LISTENER_TYPE_INDEX

        public static final int EXTENDED_LISTENER_TYPE_INDEX
        See Also:
        Constant Field Values
      • MANAGED_ATTRIBUTES

        public static final java.lang.String MANAGED_ATTRIBUTES
        If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name. Any other context attributes that are set with a name from this list will result in a call to setManagedAttribute(String, Object), which typically initiates the creation of a JMX MBean for the attribute value.
        See Also:
        Constant Field Values
      • MAX_FORM_KEYS_KEY

        public static final java.lang.String MAX_FORM_KEYS_KEY
        See Also:
        Constant Field Values
      • MAX_FORM_CONTENT_SIZE_KEY

        public static final java.lang.String MAX_FORM_CONTENT_SIZE_KEY
        See Also:
        Constant Field Values
      • DEFAULT_MAX_FORM_CONTENT_SIZE

        public static final int DEFAULT_MAX_FORM_CONTENT_SIZE
        See Also:
        Constant Field Values
    • Constructor Detail

      • ContextHandler

        public ContextHandler()
      • ContextHandler

        public ContextHandler​(java.lang.String contextPath)
      • ContextHandler

        public ContextHandler​(HandlerContainer parent,
                              java.lang.String contextPath)
    • Method Detail

      • getCurrentContext

        public static ContextHandler.Context getCurrentContext()
        Get the current ServletContext implementation.
        Returns:
        ServletContext implementation
      • getServerInfo

        public static java.lang.String getServerInfo()
      • setServerInfo

        public static void setServerInfo​(java.lang.String serverInfo)
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Overrides:
        dump in class ContainerLifeCycle
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • getAllowNullPathInfo

        @ManagedAttribute("Checks if the /context is not redirected to /context/")
        public boolean getAllowNullPathInfo()
        Returns:
        the allowNullPathInfo true if /context is not redirected to /context/
      • setAllowNullPathInfo

        public void setAllowNullPathInfo​(boolean allowNullPathInfo)
        Parameters:
        allowNullPathInfo - true if /context is not redirected to /context/
      • isUsingSecurityManager

        public boolean isUsingSecurityManager()
      • setUsingSecurityManager

        public void setUsingSecurityManager​(boolean usingSecurityManager)
      • setVirtualHosts

        public void setVirtualHosts​(java.lang.String[] vhosts)
        Set the virtual hosts for the context. Only requests that have a matching host header or fully qualified URL will be passed to that context with a virtual host name. A context with no virtual host names or a null virtual host name is available to all requests that are not served by a context with a matching virtual host name.
        Parameters:
        vhosts - Array of virtual hosts that this context responds to. A null/empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names. Hosts and wildcard hosts may be followed with '@connectorname', in which case they will match only if the the Connector.getName() for the request also matches. If an entry is just '@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.
      • addVirtualHosts

        public void addVirtualHosts​(java.lang.String[] virtualHosts)
        Either set virtual hosts or add to an existing set of virtual hosts.
        Parameters:
        virtualHosts - Array of virtual hosts that this context responds to. A null/empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names. Hosts and wildcard hosts may be followed with '@connectorname', in which case they will match only if the the Connector.getName() for the request also matches. If an entry is just '@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.
      • removeVirtualHosts

        public void removeVirtualHosts​(java.lang.String[] virtualHosts)
        Removes an array of virtual host entries, if this removes all entries the _vhosts will be set to null
        Parameters:
        virtualHosts - Array of virtual hosts that this context responds to. A null/empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names. Hosts and wildcard hosts may be followed with '@connectorname', in which case they will match only if the the Connector.getName() for the request also matches. If an entry is just '@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.
      • getVirtualHosts

        @ManagedAttribute(value="Virtual hosts accepted by the context",
                          readonly=true)
        public java.lang.String[] getVirtualHosts()
        Get the virtual hosts for the context. Only requests that have a matching host header or fully qualified URL will be passed to that context with a virtual host name. A context with no virtual host names or a null virtual host name is available to all requests that are not served by a context with a matching virtual host name.
        Returns:
        Array of virtual hosts that this context responds to. A null/empty array means any hostname is acceptable. Host names may be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names. Hosts and wildcard hosts may be followed with '@connectorname', in which case they will match only if the the Connector.getName() for the request also matches. If an entry is just '@connectorname' it will match any host if that connector was used. Note - In previous versions if one or more connectorname only entries existed and non of the connectors matched the handler would not match regardless of any hostname entries. If there is one or more connectorname only entries and one or more host only entries but no hostname and connector entries we assume the old behavior and will log a warning. The warning can be removed by removing the host entries that were previously being ignored, or modifying to include a hostname and connectorname entry.
      • getAttribute

        public java.lang.Object getAttribute​(java.lang.String name)
        Specified by:
        getAttribute in interface Attributes
      • getAttributeNames

        public java.util.Enumeration<java.lang.String> getAttributeNames()
        Specified by:
        getAttributeNames in interface Attributes
      • getAttributes

        public Attributes getAttributes()
        Returns:
        Returns the attributes.
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Returns:
        Returns the classLoader.
      • getClassPath

        @ManagedAttribute("The file classpath")
        public java.lang.String getClassPath()
        Make best effort to extract a file classpath from the context classloader
        Returns:
        Returns the classLoader.
      • getContextPath

        @ManagedAttribute("True if URLs are compacted to replace the multiple \'/\'s with a single \'/\'")
        public java.lang.String getContextPath()
        Returns:
        Returns the contextPath.
      • getContextPathEncoded

        public java.lang.String getContextPathEncoded()
        Returns:
        Returns the encoded contextPath.
      • getInitParameter

        public java.lang.String getInitParameter​(java.lang.String name)
      • setInitParameter

        public java.lang.String setInitParameter​(java.lang.String name,
                                                 java.lang.String value)
      • getInitParameterNames

        public java.util.Enumeration<java.lang.String> getInitParameterNames()
      • getInitParams

        @ManagedAttribute("Initial Parameter map for the context")
        public java.util.Map<java.lang.String,​java.lang.String> getInitParams()
        Returns:
        Returns the initParams.
      • getEventListeners

        public java.util.EventListener[] getEventListeners()
      • isProgrammaticListener

        public boolean isProgrammaticListener​(java.util.EventListener listener)
      • isDurableListener

        public boolean isDurableListener​(java.util.EventListener listener)
      • isShutdown

        @ManagedAttribute("true for graceful shutdown, which allows existing requests to complete")
        public boolean isShutdown()
        Specified by:
        isShutdown in interface Graceful
        Returns:
        true if this context is shutting down
      • shutdown

        public java.util.concurrent.Future<java.lang.Void> shutdown()
        Set shutdown status. This field allows for graceful shutdown of a context. A started context may be put into non accepting state so that existing requests can complete, but no new requests are accepted.
        Specified by:
        shutdown in interface Graceful
      • isAvailable

        public boolean isAvailable()
        Returns:
        false if this context is unavailable (sends 503)
      • setAvailable

        public void setAvailable​(boolean available)
        Set Available status.
        Parameters:
        available - true to set as enabled
      • getLogger

        public Logger getLogger()
      • setLogger

        public void setLogger​(Logger logger)
      • contextInitialized

        public void contextInitialized()
                                throws java.lang.Exception
        Call the ServletContextListeners contextInitialized methods. This can be called from a ServletHandler during the proper sequence of initializing filters, servlets and listeners. However, if there is no ServletHandler, the ContextHandler will call this method during doStart().
        Throws:
        java.lang.Exception
      • contextDestroyed

        public void contextDestroyed()
                              throws java.lang.Exception
        Call the ServletContextListeners with contextDestroyed. This method can be called from a ServletHandler in the proper sequence of destroying filters, servlets and listeners. If there is no ServletHandler, the ContextHandler must ensure these listeners are called instead.
        Throws:
        java.lang.Exception
      • checkVirtualHost

        public boolean checkVirtualHost​(Request baseRequest)
      • checkContextPath

        public boolean checkContextPath​(java.lang.String uri)
      • checkContext

        public boolean checkContext​(java.lang.String target,
                                    Request baseRequest,
                                    HttpServletResponse response)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • handle

        public void handle​(Request request,
                           java.lang.Runnable runnable)
        Handle a runnable in the scope of this context and a particular request
        Parameters:
        request - The request to scope the thread to (may be null if no particular request is in scope)
        runnable - The runnable to run.
      • handle

        public void handle​(java.lang.Runnable runnable)
      • setProtectedTargets

        public void setProtectedTargets​(java.lang.String[] targets)
        Parameters:
        targets - Array of URL prefix. Each prefix is in the form /path and will match either /path exactly or /path/anything
      • getProtectedTargets

        public java.lang.String[] getProtectedTargets()
      • removeAttribute

        public void removeAttribute​(java.lang.String name)
        Specified by:
        removeAttribute in interface Attributes
      • setAttribute

        public void setAttribute​(java.lang.String name,
                                 java.lang.Object value)
        Specified by:
        setAttribute in interface Attributes
      • setAttributes

        public void setAttributes​(Attributes attributes)
        Parameters:
        attributes - The attributes to set.
      • setManagedAttribute

        @Deprecated
        public void setManagedAttribute​(java.lang.String name,
                                        java.lang.Object value)
        Deprecated.
      • setClassLoader

        public void setClassLoader​(java.lang.ClassLoader classLoader)
        Parameters:
        classLoader - The classLoader to set.
      • setContextPath

        public void setContextPath​(java.lang.String contextPath)
        Parameters:
        contextPath - The _contextPath to set.
      • setDisplayName

        public void setDisplayName​(java.lang.String servletContextName)
        Parameters:
        servletContextName - The servletContextName to set.
      • getBaseResource

        public Resource getBaseResource()
        Returns:
        Returns the resourceBase.
      • getResourceBase

        @ManagedAttribute("document root for context")
        public java.lang.String getResourceBase()
        Returns:
        Returns the base resource as a string.
      • setBaseResource

        public void setBaseResource​(Resource base)
        Set the base resource for this context.
        Parameters:
        base - The resource used as the base for all static content of this context.
        See Also:
        setResourceBase(String)
      • setResourceBase

        public void setResourceBase​(java.lang.String resourceBase)
        Set the base resource for this context.
        Parameters:
        resourceBase - A string representing the base resource for the context. Any string accepted by Resource.newResource(String) may be passed and the call is equivalent to setBaseResource(newResource(resourceBase));
      • getMimeTypes

        public MimeTypes getMimeTypes()
        Returns:
        Returns the mimeTypes.
      • setMimeTypes

        public void setMimeTypes​(MimeTypes mimeTypes)
        Parameters:
        mimeTypes - The mimeTypes to set.
      • setWelcomeFiles

        public void setWelcomeFiles​(java.lang.String[] files)
      • getErrorHandler

        @ManagedAttribute("The error handler to use for the context")
        public ErrorHandler getErrorHandler()
        Returns:
        Returns the errorHandler.
      • setErrorHandler

        public void setErrorHandler​(ErrorHandler errorHandler)
        Parameters:
        errorHandler - The errorHandler to set.
      • getMaxFormContentSize

        @ManagedAttribute("The maximum content size")
        public int getMaxFormContentSize()
      • setMaxFormContentSize

        public void setMaxFormContentSize​(int maxSize)
        Set the maximum size of a form post, to protect against DOS attacks from large forms.
        Parameters:
        maxSize - the maximum size of the form content (in bytes)
      • getMaxFormKeys

        public int getMaxFormKeys()
      • setMaxFormKeys

        public void setMaxFormKeys​(int max)
        Set the maximum number of form Keys to protect against DOS attack from crafted hash keys.
        Parameters:
        max - the maximum number of form keys
      • isCompactPath

        public boolean isCompactPath()
        Returns:
        True if URLs are compacted to replace multiple '/'s with a single '/'
      • setCompactPath

        public void setCompactPath​(boolean compactPath)
        Parameters:
        compactPath - True if URLs are compacted to replace multiple '/'s with a single '/'
      • loadClass

        public java.lang.Class<?> loadClass​(java.lang.String className)
                                     throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException
      • addLocaleEncoding

        public void addLocaleEncoding​(java.lang.String locale,
                                      java.lang.String encoding)
      • getLocaleEncoding

        public java.lang.String getLocaleEncoding​(java.lang.String locale)
      • getLocaleEncoding

        public java.lang.String getLocaleEncoding​(java.util.Locale locale)
        Get the character encoding for a locale. The full locale name is first looked up in the map of encodings. If no encoding is found, then the locale language is looked up.
        Parameters:
        locale - a Locale value
        Returns:
        a String representing the character encoding for the locale or null if none found.
      • getLocaleEncodings

        public java.util.Map<java.lang.String,​java.lang.String> getLocaleEncodings()
        Get all of the locale encodings
        Returns:
        a map of all the locale encodings: key is name of the locale and value is the char encoding
      • getResource

        public Resource getResource​(java.lang.String path)
                             throws java.net.MalformedURLException
        Throws:
        java.net.MalformedURLException
      • checkAlias

        public boolean checkAlias​(java.lang.String path,
                                  Resource resource)
        Parameters:
        path - the path to check the alias for
        resource - the resource
        Returns:
        True if the alias is OK
      • newResource

        public Resource newResource​(java.net.URL url)
                             throws java.io.IOException
        Convert URL to Resource wrapper for Resource.newResource(URL) enables extensions to provide alternate resource implementations.
        Parameters:
        url - the url to convert to a Resource
        Returns:
        the Resource for that url
        Throws:
        java.io.IOException - if unable to create a Resource from the URL
      • newResource

        public Resource newResource​(java.net.URI uri)
                             throws java.io.IOException
        Convert URL to Resource wrapper for Resource.newResource(URL) enables extensions to provide alternate resource implementations.
        Parameters:
        uri - the URI to convert to a Resource
        Returns:
        the Resource for that URI
        Throws:
        java.io.IOException - if unable to create a Resource from the URL
      • newResource

        public Resource newResource​(java.lang.String urlOrPath)
                             throws java.io.IOException
        Convert a URL or path to a Resource. The default implementation is a wrapper for Resource.newResource(String).
        Parameters:
        urlOrPath - The URL or path to convert
        Returns:
        The Resource for the URL/path
        Throws:
        java.io.IOException - The Resource could not be created.
      • getResourcePaths

        public java.util.Set<java.lang.String> getResourcePaths​(java.lang.String path)
      • addAliasCheck

        public void addAliasCheck​(ContextHandler.AliasCheck check)
        Add an AliasCheck instance to possibly permit aliased resources
        Parameters:
        check - The alias checker
      • setAliasChecks

        public void setAliasChecks​(java.util.List<ContextHandler.AliasCheck> checks)
        Parameters:
        checks - list of AliasCheck instances
      • clearAliasChecks

        public void clearAliasChecks()
        clear the list of AliasChecks