Class WebAppContext

    • Field Detail

      • WEB_DEFAULTS_XML

        public static final java.lang.String WEB_DEFAULTS_XML
        See Also:
        Constant Field Values
      • SERVER_SYS_CLASSES

        public static final java.lang.String SERVER_SYS_CLASSES
        See Also:
        Constant Field Values
      • SERVER_SRV_CLASSES

        public static final java.lang.String SERVER_SRV_CLASSES
        See Also:
        Constant Field Values
      • DEFAULT_CONFIGURATION_CLASSES

        public static final java.lang.String[] DEFAULT_CONFIGURATION_CLASSES
      • __dftSystemClasses

        public static final java.lang.String[] __dftSystemClasses
      • __dftServerClasses

        public static final java.lang.String[] __dftServerClasses
    • Constructor Detail

      • WebAppContext

        public WebAppContext()
      • WebAppContext

        public WebAppContext​(java.lang.String webApp,
                             java.lang.String contextPath)
        Parameters:
        contextPath - The context path
        webApp - The URL or filename of the webapp directory or war file.
      • WebAppContext

        public WebAppContext​(Resource webApp,
                             java.lang.String contextPath)
        Parameters:
        contextPath - The context path
        webApp - The URL or filename of the webapp directory or war file.
      • WebAppContext

        public WebAppContext​(HandlerContainer parent,
                             java.lang.String webApp,
                             java.lang.String contextPath)
        Parameters:
        parent - The parent HandlerContainer.
        contextPath - The context path
        webApp - The URL or filename of the webapp directory or war file.
      • WebAppContext

        public WebAppContext​(HandlerContainer parent,
                             Resource webApp,
                             java.lang.String contextPath)
        Parameters:
        parent - The parent HandlerContainer.
        contextPath - The context path
        webApp - The webapp directory or war file.
      • WebAppContext

        public WebAppContext​(SessionHandler sessionHandler,
                             SecurityHandler securityHandler,
                             ServletHandler servletHandler,
                             ErrorHandler errorHandler)
        This constructor is used in the geronimo integration.
        Parameters:
        sessionHandler - SessionHandler for this web app
        securityHandler - SecurityHandler for this web app
        servletHandler - ServletHandler for this web app
        errorHandler - ErrorHandler for this web app
    • Method Detail

      • getCurrentWebAppContext

        public static WebAppContext getCurrentWebAppContext()
      • setDisplayName

        public void setDisplayName​(java.lang.String servletContextName)
        Overrides:
        setDisplayName in class ContextHandler
        Parameters:
        servletContextName - The servletContextName to set.
      • getUnavailableException

        public java.lang.Throwable getUnavailableException()
        Get an exception that caused the webapp to be unavailable
        Returns:
        A throwable if the webapp is unavailable or null
      • setResourceAlias

        public void setResourceAlias​(java.lang.String alias,
                                     java.lang.String uri)
        Set Resource Alias. Resource aliases map resource uri's within a context. They may optionally be used by a handler when looking for a resource.
        Parameters:
        alias - the alias for a resource
        uri - the uri for the resource
      • getResourceAliases

        public java.util.Map<java.lang.String,​java.lang.String> getResourceAliases()
      • setResourceAliases

        public void setResourceAliases​(java.util.Map<java.lang.String,​java.lang.String> map)
      • getResourceAlias

        public java.lang.String getResourceAlias​(java.lang.String path)
      • removeResourceAlias

        public java.lang.String removeResourceAlias​(java.lang.String alias)
      • setClassLoader

        public void setClassLoader​(java.lang.ClassLoader classLoader)
        Overrides:
        setClassLoader in class ContextHandler
        Parameters:
        classLoader - The classLoader to set.
      • getResource

        public Resource getResource​(java.lang.String uriInContext)
                             throws java.net.MalformedURLException
        Overrides:
        getResource in class ContextHandler
        Throws:
        java.net.MalformedURLException
      • isConfigurationDiscovered

        public boolean isConfigurationDiscovered()
        Is the context Automatically configured.
        Returns:
        true if configuration discovery.
      • setConfigurationDiscovered

        public void setConfigurationDiscovered​(boolean discovered)
        Set the configuration discovery mode. If configuration discovery is set to true, then the JSR315 servlet 3.0 discovered configuration features are enabled. These are:
        • Web Fragments
        • META-INF/resource directories
        Parameters:
        discovered - true if configuration discovery is enabled for automatic configuration from the context
      • preConfigure

        public void preConfigure()
                          throws java.lang.Exception
        Pre configure the web application.

        The method is normally called from AbstractLifeCycle.start(). It performs the discovery of the configurations to be applied to this context, specifically:

        Throws:
        java.lang.Exception - if unable to pre configure
      • configure

        public void configure()
                       throws java.lang.Exception
        Throws:
        java.lang.Exception
      • postConfigure

        public void postConfigure()
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getConfigurationClasses

        @ManagedAttribute(value="configuration classes used to configure webapp",
                          readonly=true)
        public java.lang.String[] getConfigurationClasses()
        Returns:
        Returns the configurations.
      • getConfigurations

        public Configuration[] getConfigurations()
        Returns:
        Returns the configurations.
      • getDefaultsDescriptor

        @ManagedAttribute(value="default web.xml deascriptor applied before standard web.xml",
                          readonly=true)
        public java.lang.String getDefaultsDescriptor()
        The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml
        Returns:
        Returns the defaultsDescriptor.
      • getOverrideDescriptor

        public java.lang.String getOverrideDescriptor()
        The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml
        Returns:
        Returns the Override Descriptor.
      • getOverrideDescriptors

        @ManagedAttribute(value="web.xml deascriptors applied after standard web.xml",
                          readonly=true)
        public java.util.List<java.lang.String> getOverrideDescriptors()
        An override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml
        Returns:
        Returns the Override Descriptor list
      • getServerClasspathPattern

        public ClasspathPattern getServerClasspathPattern()
        Returns:
        The ClasspathPattern used to match Server (hidden) classes
      • getSystemClasspathPattern

        public ClasspathPattern getSystemClasspathPattern()
        Returns:
        The ClasspathPattern used to match System (protected) classes
      • isServerClass

        public boolean isServerClass​(java.lang.Class<?> clazz)
        Description copied from interface: ClassVisibilityChecker
        Is the class a Server Class. A Server class is a class that is part of the implementation of the server and is NIT visible to a webapplication. The web application may provide it's own implementation of the class, to be loaded from WEB-INF/lib or WEB-INF/classes
        Specified by:
        isServerClass in interface ClassVisibilityChecker
        Parameters:
        clazz - The fully qualified name of the class.
        Returns:
        True if the class is a server class.
      • isSystemClass

        public boolean isSystemClass​(java.lang.Class<?> clazz)
        Description copied from interface: ClassVisibilityChecker
        Is the class a System Class. A System class is a class that is visible to a webapplication, but that cannot be overridden by the contents of WEB-INF/lib or WEB-INF/classes
        Specified by:
        isSystemClass in interface ClassVisibilityChecker
        Parameters:
        clazz - The fully qualified name of the class.
        Returns:
        True if the class is a system class.
      • loadSystemClasses

        protected void loadSystemClasses()
      • loadServerClasses

        protected void loadServerClasses()
      • getWebInf

        public Resource getWebInf()
                           throws java.io.IOException
        Throws:
        java.io.IOException
      • isDistributable

        @ManagedAttribute("web application distributable")
        public boolean isDistributable()
        Returns:
        Returns the distributable.
      • isCopyWebDir

        @ManagedAttribute(value="webdir copied on deploy (allows hot replacement on windows)",
                          readonly=true)
        public boolean isCopyWebDir()
        Returns:
        True if the webdir is copied (to allow hot replacement of jars on windows)
      • isCopyWebInf

        public boolean isCopyWebInf()
        Returns:
        True if the web-inf lib and classes directories are copied (to allow hot replacement of jars on windows)
      • isParentLoaderPriority

        @ManagedAttribute(value="parent classloader given priority",
                          readonly=true)
        public boolean isParentLoaderPriority()
        Specified by:
        isParentLoaderPriority in interface WebAppClassLoader.Context
        Returns:
        True if the classloader should delegate first to the parent classloader (standard java behaviour) or false if the classloader should first try to load from WEB-INF/lib or WEB-INF/classes (servlet spec recommendation). Default is false or can be set by the system property org.eclipse.jetty.server.webapp.parentLoaderPriority
      • getDefaultConfigurationClasses

        public static java.lang.String[] getDefaultConfigurationClasses()
      • getDefaultServerClasses

        public java.lang.String[] getDefaultServerClasses()
      • getDefaultSystemClasses

        public java.lang.String[] getDefaultSystemClasses()
      • loadConfigurations

        protected void loadConfigurations()
                                   throws java.lang.Exception
        Throws:
        java.lang.Exception
      • 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 ContextHandler
        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
      • setConfigurationClasses

        public void setConfigurationClasses​(java.lang.String[] configurations)
        Parameters:
        configurations - The configuration class names. If setConfigurations is not called these classes are used to create a configurations array.
      • setConfigurationClasses

        public void setConfigurationClasses​(java.util.List<java.lang.String> configurations)
      • setConfigurations

        public void setConfigurations​(Configuration[] configurations)
        Parameters:
        configurations - The configurations to set.
      • setDefaultsDescriptor

        public void setDefaultsDescriptor​(java.lang.String defaultsDescriptor)
        The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml
        Parameters:
        defaultsDescriptor - The defaultsDescriptor to set.
      • setOverrideDescriptor

        public void setOverrideDescriptor​(java.lang.String overrideDescriptor)
        The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml
        Parameters:
        overrideDescriptor - The overrideDescritpor to set.
      • setOverrideDescriptors

        public void setOverrideDescriptors​(java.util.List<java.lang.String> overrideDescriptors)
        The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml
        Parameters:
        overrideDescriptors - The overrideDescriptors (file or URL) to set.
      • addOverrideDescriptor

        public void addOverrideDescriptor​(java.lang.String overrideDescriptor)
        The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml
        Parameters:
        overrideDescriptor - The overrideDescriptor (file or URL) to add.
      • getDescriptor

        @ManagedAttribute(value="standard web.xml descriptor",
                          readonly=true)
        public java.lang.String getDescriptor()
        Returns:
        the web.xml descriptor to use. If set to null, WEB-INF/web.xml is used if it exists.
      • setDescriptor

        public void setDescriptor​(java.lang.String descriptor)
        Parameters:
        descriptor - the web.xml descriptor to use. If set to null, WEB-INF/web.xml is used if it exists.
      • setDistributable

        public void setDistributable​(boolean distributable)
        Parameters:
        distributable - The distributable to set.
      • setEventListeners

        public void setEventListeners​(java.util.EventListener[] eventListeners)
        Description copied from class: ContextHandler
        Set the context event listeners.
        Overrides:
        setEventListeners in class ContextHandler
        Parameters:
        eventListeners - the event listeners
        See Also:
        ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener
      • removeEventListener

        public void removeEventListener​(java.util.EventListener listener)
        Description copied from class: ContextHandler
        Remove a context event listeners.
        Overrides:
        removeEventListener in class ContextHandler
        Parameters:
        listener - the event listener to remove
        See Also:
        ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener
      • setExtractWAR

        public void setExtractWAR​(boolean extractWAR)
        Parameters:
        extractWAR - True if war files are extracted
      • setCopyWebDir

        public void setCopyWebDir​(boolean copy)
        Parameters:
        copy - True if the webdir is copied (to allow hot replacement of jars)
      • setCopyWebInf

        public void setCopyWebInf​(boolean copyWebInf)
        Parameters:
        copyWebInf - True if the web-inf lib and classes directories are copied (to allow hot replacement of jars on windows)
      • setParentLoaderPriority

        public void setParentLoaderPriority​(boolean java2compliant)
        Parameters:
        java2compliant - True if the classloader should delegate first to the parent classloader (standard java behaviour) or false if the classloader should first try to load from WEB-INF/lib or WEB-INF/classes (servlet spec recommendation). Default is false or can be set by the system property org.eclipse.jetty.server.webapp.parentLoaderPriority
      • setPermissions

        public void setPermissions​(java.security.PermissionCollection permissions)
        Parameters:
        permissions - The permissions to set.
      • setContextWhiteList

        public void setContextWhiteList​(java.lang.String[] contextWhiteList)
        Set the context white list In certain circumstances you want may want to deny access of one webapp from another when you may not fully trust the webapp. Setting this white list will enable a check when a servlet called ContextHandler.Context.getContext(String), validating that the uriInPath for the given webapp has been declaratively allows access to the context.
        Parameters:
        contextWhiteList - the whitelist of contexts for ContextHandler.Context.getContext(String)
      • setServerClasses

        public void setServerClasses​(java.lang.String[] serverClasses)
        Set the server classes patterns.

        Server classes/packages are classes used to implement the server and are hidden from the context. If the context needs to load these classes, it must have its own copy of them in WEB-INF/lib or WEB-INF/classes. A ClasspathPattern is used to match the server classes.

        Parameters:
        serverClasses - The serverClasses to set.
      • setSystemClasses

        public void setSystemClasses​(java.lang.String[] systemClasses)
        Set the system classes patterns.

        System classes/packages are classes provided by the JVM and that cannot be replaced by classes of the same name from WEB-INF, regardless of the value of setParentLoaderPriority(boolean). A ClasspathPattern is used to match the system classes.

        Parameters:
        systemClasses - The systemClasses to set.
      • setTempDirectory

        public void setTempDirectory​(java.io.File dir)
        Set temporary directory for context. The javax.servlet.context.tempdir attribute is also set.
        Parameters:
        dir - Writable temporary directory.
      • setPersistTempDirectory

        public void setPersistTempDirectory​(boolean persist)
        If true the temp directory for this webapp will be kept when the webapp stops. Otherwise, it will be deleted.
        Parameters:
        persist - true to persist the temp directory on shutdown / exit of the webapp
      • isPersistTempDirectory

        public boolean isPersistTempDirectory()
        Returns:
        true if tmp directory will persist between startups of the webapp
      • setWar

        public void setWar​(java.lang.String war)
        Set the war of the webapp. From this value a ContextHandler.setResourceBase(String) value is computed by WebInfConfiguration, which may be changed from the war URI by unpacking and/or copying.
        Parameters:
        war - The war to set as a file name or URL.
      • setWarResource

        public void setWarResource​(Resource war)
        Set the war of the webapp as a Resource.
        Parameters:
        war - The war to set as a Resource.
        See Also:
        setWar(String)
      • setExtraClasspath

        public void setExtraClasspath​(java.lang.String extraClasspath)
        Parameters:
        extraClasspath - Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
      • isLogUrlOnStart

        public boolean isLogUrlOnStart()
      • setLogUrlOnStart

        public void setLogUrlOnStart​(boolean logOnStart)
        Sets whether or not the web app name and URL is logged on startup
        Parameters:
        logOnStart - whether or not the log message is created
      • isAllowDuplicateFragmentNames

        public boolean isAllowDuplicateFragmentNames()
      • setAllowDuplicateFragmentNames

        public void setAllowDuplicateFragmentNames​(boolean allowDuplicateFragmentNames)
      • setThrowUnavailableOnStartupException

        public void setThrowUnavailableOnStartupException​(boolean throwIfStartupException)
      • isThrowUnavailableOnStartupException

        public boolean isThrowUnavailableOnStartupException()
      • startWebapp

        protected void startWebapp()
                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • stopWebapp

        protected void stopWebapp()
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setServletSecurity

        public java.util.Set<java.lang.String> setServletSecurity​(javax.servlet.ServletRegistration.Dynamic registration,
                                                                  javax.servlet.ServletSecurityElement servletSecurityElement)
        Description copied from class: ServletContextHandler
        Delegate for ServletRegistration.Dynamic.setServletSecurity method
        Overrides:
        setServletSecurity in class ServletContextHandler
        Parameters:
        registration - ServletRegistration.Dynamic instance that setServletSecurity was called on
        servletSecurityElement - new security info
        Returns:
        the set of exact URL mappings currently associated with the registration that are also present in the web.xml security constraints and thus will be unaffected by this call.
      • getMetaData

        public MetaData getMetaData()
      • addServerClasses

        public static void addServerClasses​(Server server,
                                            java.lang.String... pattern)
      • addSystemClasses

        public static void addSystemClasses​(Server server,
                                            java.lang.String... pattern)