## org.mortbay.jetty.webapp
Class WebAppContext

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.handler.AbstractHandler
              org.mortbay.jetty.handler.AbstractHandlerContainer
                  org.mortbay.jetty.handler.HandlerWrapper
                      org.mortbay.jetty.handler.ContextHandler
                          org.mortbay.jetty.servlet.Context
                              org.mortbay.jetty.webapp.WebAppContext

All Implemented Interfaces:
  LifeCycle, Handler, HandlerContainer, Server.Graceful, Attributes

Direct Known Subclasses:
  Jetty6PluginWebAppContext

    public class WebAppContext

extends Context

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

Author:
  gregw

Nested Class Summary

Nested classes/interfaces inherited from class org.mortbay.jetty.servlet.Context
`Context.SContext`

Field Summary
`static String` `ERROR_PAGE`
`static String` `WEB_DEFAULTS_XML`

Fields inherited from class org.mortbay.jetty.servlet.Context
`_securityHandler, _servletHandler, _sessionHandler, NO_SECURITY, NO_SESSIONS, SECURITY, SESSIONS`

Fields inherited from class org.mortbay.jetty.handler.ContextHandler
`_scontext`

Fields inherited from class org.mortbay.jetty.handler.AbstractHandler
`_string`

Fields inherited from interface org.mortbay.jetty.Handler
`ALL, DEFAULT, ERROR, FORWARD, INCLUDE, REQUEST`

Constructor Summary
`WebAppContext()`
`WebAppContext(HandlerContainer parent, String webApp, String contextPath)`
`WebAppContext(SecurityHandler securityHandler, SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler)`
`WebAppContext(String webApp, String contextPath)`

Method Summary
`void` `addEventListener(EventListener listener)` Add EventListener Conveniance method that calls `setEventListeners(EventListener[])`
`static void` `addWebApplications(HandlerContainer contexts, String webapps, String defaults, boolean extract, boolean java2CompliantClassLoader)` Deprecated. use `WebAppDeployer` or `ContextDeployer`
`static void` `addWebApplications(HandlerContainer contexts, String webapps, String defaults, String[] configurations, boolean extract, boolean java2CompliantClassLoader)` Deprecated. use `WebAppDeployer` or `ContextDeployer`
`static void` `addWebApplications(Server server, String webapps, String defaults, boolean extract, boolean java2CompliantClassLoader)` Deprecated. use `WebAppDeployer` or `ContextDeployer`
`static void` `addWebApplications(Server server, String webapps, String defaults, String[] configurations, boolean extract, boolean java2CompliantClassLoader)` Deprecated. use `WebAppDeployer` or `ContextDeployer`
`protected void` `doStart()`
`protected void` `doStop()`
`void` `dumpUrl()`
`String[]` `getConfigurationClasses()`
`Configuration[]` `getConfigurations()`
`static ContextHandler` `getCurrentWebAppContext()`
`String` `getDefaultsDescriptor()` The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml
`String` `getDescriptor()`
`String` `getExtraClasspath()`
`String` `getOverrideDescriptor()` The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml
`PermissionCollection` `getPermissions()`
`Resource` `getResource(String uriInContext)`
`String` `getResourceAlias(String alias)`
`Map` `getResourceAliases()`
`String[]` `getServerClasses()`
`String[]` `getSystemClasses()`
`File` `getTempDirectory()` Get a temporary directory in which to unpack the war etc etc.
`String` `getWar()`
`Resource` `getWebInf()`
`void` `handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)` Handle a request.
`boolean` `isCopyWebDir()`
`boolean` `isDistributable()`
`boolean` `isExtractWAR()`
`boolean` `isLogUrlOnStart()`
`boolean` `isParentLoaderPriority()`
`protected boolean` `isProtectedTarget(String target)` Check the target.
`boolean` `isTempWorkDirectory()` Check if the _tmpDir itself is called "work", or if the _tmpDir is in a directory called "work".
`protected void` `loadConfigurations()`
`String` `removeResourceAlias(String alias)`
`protected void` `resolveWebApp()` Resolve Web App directory If the BaseResource has not been set, use the war resource to derive a webapp resource (expanding WAR if required).
`void` `setClassLoader(ClassLoader classLoader)`
`void` `setConfigurationClasses(String[] configurations)`
`void` `setConfigurations(Configuration[] configurations)`
`void` `setCopyWebDir(boolean copy)`
`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
`void` `setDescriptor(String descriptor)`
`void` `setDistributable(boolean distributable)`
`void` `setEventListeners(EventListener[] eventListeners)`
`void` `setExtraClasspath(String extraClasspath)`
`void` `setExtractWAR(boolean extractWAR)`
`void` `setLogUrlOnStart(boolean logOnStart)` Sets whether or not the web app name and URL is logged on startup
`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
`void` `setParentLoaderPriority(boolean java2compliant)`
`void` `setPermissions(PermissionCollection permissions)`
`void` `setResourceAlias(String alias, String uri)` Set Resource Alias.
`void` `setResourceAliases(Map map)`
`void` `setServerClasses(String[] serverClasses)`
`void` `setSystemClasses(String[] systemClasses)`
`void` `setTempDirectory(File dir)` Set temporary directory for context.
`void` `setWar(String war)`
`protected void` `startContext()`
`String` `toString()`

Methods inherited from class org.mortbay.jetty.servlet.Context
`addFilter, addFilter, addFilter, addServlet, addServlet, addServlet, getSecurityHandler, getServletHandler, getSessionHandler, setSecurityHandler, setServletHandler, setSessionHandler`

Methods inherited from class org.mortbay.jetty.handler.ContextHandler

`addLocaleEncoding, clearAttributes, getAllowNullPathInfo, getAttribute, getAttributeNames, getAttributes, getBaseResource, getClassLoader, getClassPath, getConnectorNames, getContextPath, getCurrentContext, getDisplayName, getErrorHandler, getEventListeners, getHosts, getInitParameter, getInitParameterNames, getInitParams, getLocaleEncoding, getMaxFormContentSize, getMimeTypes, getResourceBase, getResourcePaths, getServletContext, getVirtualHosts, getWelcomeFiles, isCompactPath, isShutdown, loadClass, removeAttribute, setAllowNullPathInfo, setAttribute, setAttributes, setBaseResource, setCompactPath, setConnectorNames, setContextPath, setDisplayName, setErrorHandler, setHosts, setInitParams, setMaxFormContentSize, setMimeTypes, setResourceBase, setServer, setShutdown, setVirtualHosts, setWelcomeFiles`

Methods inherited from class org.mortbay.jetty.handler.HandlerWrapper
`addHandler, expandChildren, getHandler, removeHandler, setHandler`

Methods inherited from class org.mortbay.jetty.handler.AbstractHandlerContainer
`expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

Methods inherited from class org.mortbay.jetty.handler.AbstractHandler
`destroy, getServer`

Methods inherited from class org.mortbay.component.AbstractLifeCycle
`isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, start, stop`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.mortbay.component.LifeCycle
`isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, start, stop`

Field Detail

### WEB_DEFAULTS_XML

    public static final String WEB_DEFAULTS_XML

See Also:
  Constant Field Values

### ERROR_PAGE

    public static final String ERROR_PAGE

See Also:
  Constant Field Values

Constructor Detail

### 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(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(SecurityHandler securityHandler,
                         SessionHandler sessionHandler,
                         ServletHandler servletHandler,
                         ErrorHandler errorHandler)

Method Detail

### getCurrentWebAppContext

    public static ContextHandler getCurrentWebAppContext()

### addWebApplications

    public static void addWebApplications(Server server,
                                          String webapps,
                                          String defaults,
                                          boolean extract,
                                          boolean java2CompliantClassLoader)
                                   throws IOException

  Deprecated. use `WebAppDeployer` or `ContextDeployer`

  Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp matches the rootWebApp it is added as the "/" context.

  Parameters:
    `server` - Must not be `null`
    `webapps` - Directory file name or URL to look for auto webapplication.
    `defaults` - The defaults xml filename or URL which is loaded before any in the web app. Must respect the web.dtd. If null the default defaults file is used. If the empty string, then no defaults file is used.
    `extract` - If true, extract war files
    `java2CompliantClassLoader` - True if java2 compliance is applied to all webapplications
  Throws:
    `IOException`

### addWebApplications

    public static void addWebApplications(Server server,
                                          String webapps,
                                          String defaults,
                                          String[] configurations,
                                          boolean extract,
                                          boolean java2CompliantClassLoader)
                                   throws IOException

  Deprecated. use `WebAppDeployer` or `ContextDeployer`

  Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp matches the rootWebApp it is added as the "/" context.

  Parameters:
    `server` - Must not be `null`.
    `webapps` - Directory file name or URL to look for auto webapplication.
    `defaults` - The defaults xml filename or URL which is loaded before any in the web app. Must respect the web.dtd. If null the default defaults file is used. If the empty string, then no defaults file is used.
    `configurations` - Array of classnames of `Configuration` implementations to apply.
    `extract` - If true, extract war files
    `java2CompliantClassLoader` - True if java2 compliance is applied to all webapplications
  Throws:
    `IOException`
    `IllegalAccessException`
    `InstantiationException`

### addWebApplications

    public static void addWebApplications(HandlerContainer contexts,
                                          String webapps,
                                          String defaults,
                                          boolean extract,
                                          boolean java2CompliantClassLoader)
                                   throws IOException

  Deprecated. use `WebAppDeployer` or `ContextDeployer`

  Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp is called "root" it is added as the "/" context.

  Parameters:
    `contexts` - A HandlerContainer to which the contexts will be added
    `webapps` - Directory file name or URL to look for auto webapplication.
    `defaults` - The defaults xml filename or URL which is loaded before any in the web app. Must respect the web.dtd. If null the default defaults file is used. If the empty string, then no defaults file is used.
    `configurations` - Array of classnames of `Configuration` implementations to apply.
    `extract` - If true, extract war files
    `java2CompliantClassLoader` - True if java2 compliance is applied to all webapplications
  Throws:
    `IOException`
    `IllegalAccessException`
    `InstantiationException`

### addWebApplications

    public static void addWebApplications(HandlerContainer contexts,
                                          String webapps,
                                          String defaults,
                                          String[] configurations,
                                          boolean extract,
                                          boolean java2CompliantClassLoader)
                                   throws IOException

  Deprecated. use `WebAppDeployer` or `ContextDeployer`

  Add Web Applications. Add auto webapplications to the server. The name of the webapp directory or war is used as the context name. If the webapp is called "root" it is added as the "/" context.

  Parameters:
    `contexts` - A HandlerContainer to which the contexts will be added
    `webapps` - Directory file name or URL to look for auto webapplication.
    `defaults` - The defaults xml filename or URL which is loaded before any in the web app. Must respect the web.dtd. If null the default defaults file is used. If the empty string, then no defaults file is used.
    `configurations` - Array of classnames of `Configuration` implementations to apply.
    `extract` - If true, extract war files
    `java2CompliantClassLoader` - True if java2 compliance is applied to all webapplications
  Throws:
    `IOException`
    `IllegalAccessException`
    `InstantiationException`

### 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` -
    `uri` -

### getResourceAliases

    public Map getResourceAliases()

### setResourceAliases

    public void setResourceAliases(Map map)

### getResourceAlias

    public String getResourceAlias(String alias)

### removeResourceAlias

    public String removeResourceAlias(String alias)

### setClassLoader

    public void setClassLoader(ClassLoader classLoader)

  Overrides:
    `setClassLoader` in class `ContextHandler`
  Parameters:
    `classLoader` - The classLoader to set.

### getResource

    public Resource getResource(String uriInContext)
                         throws MalformedURLException

  Overrides:
    `getResource` in class `ContextHandler`
  Throws:
    `MalformedURLException`

### handle

    public void handle(String target,
                       HttpServletRequest request,
                       HttpServletResponse response,
                       int dispatch)
                throws IOException,
                       ServletException

  Description copied from interface: `Handler`
  Handle a request.

  Specified by:
    `handle` in interface `Handler`
  Overrides:
    `handle` in class `ContextHandler`
  Parameters:
    `target` - The target of the request - either a URI or a name.
    `request` - The request either as the `Request` object or a wrapper of that request. The `HttpConnection.getCurrentConnection()` method can be used access the Request object if required.
    `response` - The response as the `Response` object or a wrapper of that request. The `HttpConnection.getCurrentConnection()` method can be used access the Response object if required.
    `dispatch` - The dispatch mode: `Handler.REQUEST`, `Handler.FORWARD`, `Handler.INCLUDE`, `Handler.ERROR`
  Throws:
    `IOException`
    `ServletException`
  See Also:
    `ContextHandler.handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)`

### doStart

    protected void doStart()
                    throws Exception

  Overrides:
    `doStart` in class `ContextHandler`
  Throws:
    `Exception`

### dumpUrl

    public void dumpUrl()

### doStop

    protected void doStop()
                   throws Exception

  Overrides:
    `doStop` in class `ContextHandler`
  Throws:
    `Exception`

### getConfigurationClasses

    public String[] getConfigurationClasses()

  Returns:
    Returns the configurations.

### getConfigurations

    public Configuration[] getConfigurations()

  Returns:
    Returns the configurations.

### getDefaultsDescriptor

    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.

### getPermissions

    public PermissionCollection getPermissions()

  Returns:
    Returns the permissions.

### getServerClasses

    public String[] getServerClasses()

  Returns:
    Returns the serverClasses.

### getSystemClasses

    public String[] getSystemClasses()

  Returns:
    Returns the systemClasses.

### getTempDirectory

    public File getTempDirectory()

  Get a temporary directory in which to unpack the war etc etc. The algorithm for determining this is to check these alternatives in the order shown:

  A. Try to use an explicit directory specifically for this webapp:

  1. Iff an explicit directory is set for this webapp, use it. Do NOT set delete on exit.
  2. Iff javax.servlet.context.tempdir context attribute is set for this webapp && exists && writeable, then use it. Do NOT set delete on exit.

  B. Create a directory based on global settings. The new directory will be called "Jetty_"+host+"_"+port+"__"+context+"_"+virtualhost Work out where to create this directory:

  1. Iff $(jetty.home)/work exists create the directory there. Do NOT set delete on exit. Do NOT delete contents if dir already exists.
  2. Iff WEB-INF/work exists create the directory there. Do NOT set delete on exit. Do NOT delete contents if dir already exists.
  3. Else create dir in $(java.io.tmpdir). Set delete on exit. Delete contents if dir already exists.

  Returns:

### isTempWorkDirectory

    public boolean isTempWorkDirectory()

  Check if the _tmpDir itself is called "work", or if the _tmpDir is in a directory called "work".

  Returns:

### getWar

    public String getWar()

  Returns:
    Returns the war as a file or URL string (Resource)

### getWebInf

    public Resource getWebInf()
                       throws IOException

  Throws:
    `IOException`

### isDistributable

    public boolean isDistributable()

  Returns:
    Returns the distributable.

### isExtractWAR

    public boolean isExtractWAR()

  Returns:
    Returns the extractWAR.

### isCopyWebDir

    public boolean isCopyWebDir()

  Returns:
    True if the webdir is copied (to allow hot replacement of jars)

### isParentLoaderPriority

    public boolean isParentLoaderPriority()

  Returns:
    Returns the java2compliant.

### loadConfigurations

    protected void loadConfigurations()
                               throws Exception

  Throws:
    `Exception`

### isProtectedTarget

    protected boolean isProtectedTarget(String target)

  Description copied from class: `ContextHandler`
  Check the target. Called by `ContextHandler.handle(String, HttpServletRequest, HttpServletResponse, int)` when a target within a context is determined. If the target is protected, 404 is returned. The default implementation always returns false.

  Overrides:
    `isProtectedTarget` in class `ContextHandler`
  See Also:
    `isProtectedTarget(String)`

### toString

    public String toString()

  Overrides:
    `toString` in class `ContextHandler`

### resolveWebApp

    protected void resolveWebApp()
                          throws IOException

  Resolve Web App directory If the BaseResource has not been set, use the war resource to derive a webapp resource (expanding WAR if required).

  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.

### 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:
    `defaultsDescriptor` - The overrideDescritpor to set.

### getDescriptor

    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 `ContextHandler`

### addEventListener

    public void addEventListener(EventListener listener)

  Add EventListener Conveniance method that calls `setEventListeners(EventListener[])`

  Overrides:
    `addEventListener` in class `ContextHandler`
  Parameters:
    `listener` -

### 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)

### setParentLoaderPriority

    public void setParentLoaderPriority(boolean java2compliant)

  Parameters:
    `java2compliant` - The java2compliant to set.

### setPermissions

    public void setPermissions(PermissionCollection permissions)

  Parameters:
    `permissions` - The permissions to set.

### setServerClasses

    public void setServerClasses(String[] serverClasses)

  Parameters:
    `serverClasses` - The serverClasses to set.

### setSystemClasses

    public void setSystemClasses(String[] systemClasses)

  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.

### setWar

    public void setWar(String war)

  Parameters:
    `war` - The war to set as a file name or URL

### getExtraClasspath

    public String getExtraClasspath()

  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

### startContext

    protected void startContext()
                         throws Exception

  Overrides:
    `startContext` in class `Context`
  Throws:
    `Exception`
  See Also:
    `ContextHandler.startContext()`

Copyright © 2008 Mort Bay Consulting. All Rights Reserved.