Class WebAppContext

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.server.handler.AbstractHandler
org.eclipse.jetty.server.handler.AbstractHandlerContainer
org.eclipse.jetty.server.handler.HandlerWrapper
org.eclipse.jetty.server.handler.ScopedHandler
org.eclipse.jetty.server.handler.ContextHandler
org.eclipse.jetty.servlet.ServletContextHandler
org.eclipse.jetty.webapp.WebAppContext
All Implemented Interfaces:
org.eclipse.jetty.server.Handler, org.eclipse.jetty.server.HandlerContainer, org.eclipse.jetty.util.Attributes, org.eclipse.jetty.util.ClassVisibilityChecker, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.Graceful, org.eclipse.jetty.util.component.LifeCycle, WebAppClassLoader.Context

@ManagedObject("Web Application ContextHandler") public class WebAppContext extends ServletContextHandler implements WebAppClassLoader.Context
Web Application Context Handler.

The WebAppContext handler is an extension of ContextHandler that coordinates the construction and configuration of nested handlers: ConstraintSecurityHandler, SessionHandler and ServletHandler. The handlers are configured by pluggable configuration classes, with the default being WebXmlConfiguration and JettyWebXmlConfiguration.

  • Field Details

  • Constructor Details

    • WebAppContext

      public WebAppContext()
    • WebAppContext

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

      public WebAppContext(org.eclipse.jetty.util.resource.Resource webApp, String contextPath)
      Parameters:
      contextPath - The context path
      webApp - The URL or filename of the webapp directory or war file.
    • WebAppContext

      public WebAppContext(org.eclipse.jetty.server.HandlerContainer parent, String webApp, 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(org.eclipse.jetty.server.HandlerContainer parent, org.eclipse.jetty.util.resource.Resource webApp, String contextPath)
      Parameters:
      parent - The parent HandlerContainer.
      contextPath - The context path
      webApp - The webapp directory or war file.
    • WebAppContext

      public WebAppContext(org.eclipse.jetty.server.session.SessionHandler sessionHandler, org.eclipse.jetty.security.SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.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
    • WebAppContext

      public WebAppContext(org.eclipse.jetty.server.HandlerContainer parent, String contextPath, org.eclipse.jetty.server.session.SessionHandler sessionHandler, org.eclipse.jetty.security.SecurityHandler securityHandler, ServletHandler servletHandler, org.eclipse.jetty.server.handler.ErrorHandler errorHandler, int options)
      This constructor is used in the geronimo integration.
      Parameters:
      parent - the parent handler
      contextPath - the context path
      sessionHandler - SessionHandler for this web app
      securityHandler - SecurityHandler for this web app
      servletHandler - ServletHandler for this web app
      errorHandler - ErrorHandler for this web app
      options - the options (ServletContextHandler.SESSIONS and/or ServletContextHandler.SECURITY)
  • Method Details

    • getCurrentWebAppContext

      public static WebAppContext getCurrentWebAppContext()
    • setDisplayName

      public void setDisplayName(String servletContextName)
      Overrides:
      setDisplayName in class org.eclipse.jetty.server.handler.ContextHandler
      Parameters:
      servletContextName - The servletContextName to set.
    • getUnavailableException

      public 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(String alias, 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 Map<String,String> getResourceAliases()
    • setResourceAliases

      public void setResourceAliases(Map<String,String> map)
    • getResourceAlias

      public String getResourceAlias(String path)
    • removeResourceAlias

      public String removeResourceAlias(String alias)
    • setClassLoader

      public void setClassLoader(ClassLoader classLoader)
      Overrides:
      setClassLoader in class org.eclipse.jetty.server.handler.ContextHandler
    • getResource

      public org.eclipse.jetty.util.resource.Resource getResource(String uriInContext) throws MalformedURLException
      Overrides:
      getResource in class org.eclipse.jetty.server.handler.ContextHandler
      Throws:
      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 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:
      Exception - if unable to pre configure
    • configure

      public void configure() throws Exception
      Throws:
      Exception
    • postConfigure

      public void postConfigure() throws Exception
      Throws:
      Exception
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class ServletContextHandler
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class ServletContextHandler
      Throws:
      Exception
    • destroy

      public void destroy()
      Specified by:
      destroy in interface org.eclipse.jetty.util.component.Destroyable
      Specified by:
      destroy in interface org.eclipse.jetty.server.Handler
      Overrides:
      destroy in class org.eclipse.jetty.server.handler.HandlerWrapper
    • getConfigurationClasses

      @ManagedAttribute(value="configuration classes used to configure webapp", readonly=true) public 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 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 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 List<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
    • getPermissions

      public PermissionCollection getPermissions()
      Specified by:
      getPermissions in interface WebAppClassLoader.Context
      Returns:
      Returns the permissions.
    • getServerClasses

      @ManagedAttribute(value="classes and packages hidden by the context classloader", readonly=true) public String[] getServerClasses()
      Returns:
      Returns the serverClasses.
      See Also:
    • getServerClasspathPattern

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

      @Deprecated public void addServerClass(String classOrPackageOrLocation)
      Parameters:
      classOrPackageOrLocation - pattern (see ClasspathPattern
    • prependServerClass

      @Deprecated public void prependServerClass(String classOrPackage)
      Prepend to the list of Server classes.
      Parameters:
      classOrPackage - A pattern.
      See Also:
    • getSystemClasses

      @ManagedAttribute(value="classes and packages given priority by context classloader", readonly=true) public String[] getSystemClasses()
      Returns:
      Returns the systemClasses.
      See Also:
    • getSystemClasspathPattern

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

      @Deprecated public void addSystemClass(String classOrPackage)
      Parameters:
      classOrPackage - pattern
    • prependSystemClass

      @Deprecated public void prependSystemClass(String classOrPackage)
      Prepend to the list of System classes.
      Parameters:
      classOrPackage - A pattern.
      See Also:
    • isServerClass

      @Deprecated public boolean isServerClass(String name)
      Parameters:
      name - class name
      Returns:
      true if matched by getServerClasspathPattern()
    • isSystemClass

      @Deprecated public boolean isSystemClass(String name)
      Parameters:
      name - class name
      Returns:
      true if matched by getServerClasspathPattern()
    • isServerClass

      public boolean isServerClass(Class<?> clazz)
      Specified by:
      isServerClass in interface org.eclipse.jetty.util.ClassVisibilityChecker
    • isSystemClass

      public boolean isSystemClass(Class<?> clazz)
      Specified by:
      isSystemClass in interface org.eclipse.jetty.util.ClassVisibilityChecker
    • isServerResource

      public boolean isServerResource(String name, URL parentUrl)
      Specified by:
      isServerResource in interface WebAppClassLoader.Context
    • isSystemResource

      public boolean isSystemResource(String name, URL webappUrl)
      Specified by:
      isSystemResource in interface WebAppClassLoader.Context
    • loadSystemClasses

      protected void loadSystemClasses()
    • loadServerClasses

      protected void loadServerClasses()
    • getWar

      @ManagedAttribute(value="war file location", readonly=true) public String getWar()
      Returns:
      Returns the war as a file or URL string (Resource). The war may be different to the @link ContextHandler.getResourceBase() if the war has been expanded and/or copied.
    • getWebInf

      public org.eclipse.jetty.util.resource.Resource getWebInf() throws IOException
      Throws:
      IOException
    • isDistributable

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

      @ManagedAttribute(value="extract war", readonly=true) public boolean isExtractWAR()
      Returns:
      Returns the extractWAR.
    • 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 String[] getDefaultConfigurationClasses()
    • getDefaultServerClasses

      public String[] getDefaultServerClasses()
    • getDefaultSystemClasses

      public String[] getDefaultSystemClasses()
    • loadConfigurations

      protected void loadConfigurations() throws Exception
      Throws:
      Exception
    • toString

      public String toString()
      Overrides:
      toString in class org.eclipse.jetty.server.handler.ContextHandler
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Specified by:
      dump in interface org.eclipse.jetty.util.component.Dumpable
      Overrides:
      dump in class org.eclipse.jetty.server.handler.ContextHandler
      Throws:
      IOException
    • setConfigurationClasses

      public void setConfigurationClasses(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(List<String> configurations)
    • setConfigurations

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

      public void setDefaultsDescriptor(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(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(List<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(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 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(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(EventListener[] eventListeners)
      Overrides:
      setEventListeners in class org.eclipse.jetty.server.handler.ContextHandler
    • removeEventListener

      public void removeEventListener(EventListener listener)
      Overrides:
      removeEventListener in class org.eclipse.jetty.server.handler.ContextHandler
    • 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(PermissionCollection permissions)
      Parameters:
      permissions - The permissions to set.
    • setContextWhiteList

      public void setContextWhiteList(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(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(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(File dir)
      Set temporary directory for context. The javax.servlet.context.tempdir attribute is also set.
      Parameters:
      dir - Writable temporary directory.
    • getTempDirectory

      @ManagedAttribute(value="temporary directory location", readonly=true) public File getTempDirectory()
    • 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(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(org.eclipse.jetty.util.resource.Resource war)
      Set the war of the webapp as a Resource.
      Parameters:
      war - The war to set as a Resource.
      See Also:
    • getExtraClasspath

      @ManagedAttribute(value="extra classpath for context classloader", readonly=true) public String getExtraClasspath()
      Specified by:
      getExtraClasspath in interface WebAppClassLoader.Context
      Returns:
      Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
    • setExtraClasspath

      public void setExtraClasspath(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
    • setServer

      public void setServer(org.eclipse.jetty.server.Server server)
      Specified by:
      setServer in interface org.eclipse.jetty.server.Handler
      Overrides:
      setServer in class org.eclipse.jetty.server.handler.ContextHandler
    • isAllowDuplicateFragmentNames

      public boolean isAllowDuplicateFragmentNames()
    • setAllowDuplicateFragmentNames

      public void setAllowDuplicateFragmentNames(boolean allowDuplicateFragmentNames)
    • setThrowUnavailableOnStartupException

      public void setThrowUnavailableOnStartupException(boolean throwIfStartupException)
    • isThrowUnavailableOnStartupException

      public boolean isThrowUnavailableOnStartupException()
    • startContext

      protected void startContext() throws Exception
      Overrides:
      startContext in class ServletContextHandler
      Throws:
      Exception
    • stopContext

      protected void stopContext() throws Exception
      Overrides:
      stopContext in class ServletContextHandler
      Throws:
      Exception
    • startWebapp

      protected void startWebapp() throws Exception
      Throws:
      Exception
    • stopWebapp

      protected void stopWebapp() throws Exception
      Throws:
      Exception
    • setServletSecurity

      public Set<String> setServletSecurity(javax.servlet.ServletRegistration.Dynamic registration, javax.servlet.ServletSecurityElement servletSecurityElement)
      Overrides:
      setServletSecurity in class ServletContextHandler
    • getMetaData

      public MetaData getMetaData()
    • addServerClasses

      public static void addServerClasses(org.eclipse.jetty.server.Server server, String... pattern)
    • addSystemClasses

      public static void addSystemClasses(org.eclipse.jetty.server.Server server, String... pattern)