org.mortbay.jetty.webapp
Class WebAppContext

java.lang.Object
  extended by org.mortbay.component.AbstractLifeCycle
      extended by org.mortbay.jetty.handler.AbstractHandler
          extended by org.mortbay.jetty.handler.WrappedHandler
              extended by org.mortbay.jetty.handler.ContextHandler
                  extended by org.mortbay.jetty.webapp.WebAppContext
All Implemented Interfaces:
LifeCycle, Handler, Attributes

public class WebAppContext
extends ContextHandler

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
 class WebAppContext.WebAppErrorHandler
           
 
Nested classes/interfaces inherited from class org.mortbay.jetty.handler.ContextHandler
ContextHandler.Context
 
Field Summary
private static String[] __dftConfigurationClasses
           
private  String[] _configurationClasses
           
private  Configuration[] _configurations
           
private  String _defaultsDescriptor
           
private  boolean _distributable
           
private  boolean _extractWAR
           
private  boolean _ownClassLoader
           
private  boolean _parentLoaderPriority
           
private  PermissionCollection _permissions
           
private  Map _resourceAliases
           
private  SecurityHandler _securityHandler
           
private  String[] _serverClasses
           
private  ServletHandler _servletHandler
           
private  SessionHandler _sessionHandler
           
private  String[] _systemClasses
           
private  File _tmpDir
           
private  String _war
           
 
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(SecurityHandler securityHandler, SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
           
 
Method Summary
 void addEventListener(EventListener listener)
          Add EventListener Conveniance method that calls setEventListeners(EventListener[])
static void addWebApplications(Server server, String webapps, String defaults, boolean extract, boolean java2CompliantClassLoader)
          Add Web Applications.
protected  void doStart()
           
protected  void doStop()
           
 String[] getConfigurationClasses()
           
 Configuration[] getConfigurations()
           
 String getDefaultsDescriptor()
           
 PermissionCollection getPermissions()
           
 Resource getResource(String uriInContext)
           
 String getResourceAlias(String alias)
           
 Map getResourceAliases()
           
 SecurityHandler getSecurityHandler()
           
 String[] getServerClasses()
           
 ServletHandler getServletHandler()
           
 SessionHandler getSessionHandler()
           
 String[] getSystemClasses()
           
 File getTempDirectory()
           
 String getWar()
           
 Resource getWebInf()
           
 boolean isDistributable()
           
 boolean isExtractWAR()
           
 boolean isParentLoaderPriority()
           
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 setConfigurationClasses(String[] configurations)
           
 void setConfigurations(Configuration[] configurations)
           
 void setDefaultsDescriptor(String defaultsDescriptor)
           
 void setDistributable(boolean distributable)
           
 void setEventListeners(EventListener[] eventListeners)
           
 void setExtractWAR(boolean extractWAR)
           
 void setParentLoaderPriority(boolean java2compliant)
           
 void setPermissions(PermissionCollection permissions)
           
 void setResourceAlias(String alias, String uri)
          Set Resource Alias.
 void setResourceAliases(Map map)
           
 void setSecurityHandler(SecurityHandler securityHandler)
           
 void setServer(Server server)
           
 void setServerClasses(String[] serverClasses)
           
 void setServletHandler(ServletHandler servletHandler)
           
 void setSessionHandler(SessionHandler sessionHandler)
           
 void setSystemClasses(String[] systemClasses)
           
 void setTempDirectory(File dir)
          Set temporary directory for context.
 void setWar(String war)
           
protected  void startContext()
           
 
Methods inherited from class org.mortbay.jetty.handler.ContextHandler
addLocaleEncoding, clearAttributes, getAttribute, getAttributeNames, getAttributes, getBaseResource, getClassLoader, getContextPath, getCurrentContext, getDisplayName, getErrorHandler, getEventListeners, getHosts, getInitParameter, getInitParameterNames, getInitParams, getLocaleEncoding, getMimeTypes, getResourceBase, getResourcePaths, getVirtualHosts, getWelcomeFiles, handle, loadClass, removeAttribute, setAttribute, setAttributes, setBaseResource, setClassLoader, setContextPath, setDisplayName, setErrorHandler, setHosts, setInitParams, setMimeTypes, setResourceBase, setVirtualHosts, setWelcomeFiles, toString
 
Methods inherited from class org.mortbay.jetty.handler.WrappedHandler
getHandler, setHandler
 
Methods inherited from class org.mortbay.jetty.handler.AbstractHandler
getServer
 
Methods inherited from class org.mortbay.component.AbstractLifeCycle
isFailed, isRunning, isStarted, isStarting, 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, isStopping, start, stop
 

Field Detail

__dftConfigurationClasses

private static String[] __dftConfigurationClasses

_configurationClasses

private String[] _configurationClasses

_configurations

private Configuration[] _configurations

_defaultsDescriptor

private String _defaultsDescriptor

_distributable

private boolean _distributable

_extractWAR

private boolean _extractWAR

_parentLoaderPriority

private boolean _parentLoaderPriority

_permissions

private PermissionCollection _permissions

_securityHandler

private SecurityHandler _securityHandler

_servletHandler

private ServletHandler _servletHandler

_sessionHandler

private SessionHandler _sessionHandler

_systemClasses

private String[] _systemClasses

_serverClasses

private String[] _serverClasses

_tmpDir

private File _tmpDir

_war

private String _war

_resourceAliases

private transient Map _resourceAliases

_ownClassLoader

private transient boolean _ownClassLoader
Constructor Detail

WebAppContext

public WebAppContext()

WebAppContext

public WebAppContext(SecurityHandler securityHandler,
                     SessionHandler sessionHandler,
                     ServletHandler servletHandler,
                     ErrorHandler errorHandler)
Method Detail

addWebApplications

public static void addWebApplications(Server server,
                                      String webapps,
                                      String defaults,
                                      boolean extract,
                                      boolean java2CompliantClassLoader)
                               throws IOException
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:
host - Virtual host name or 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

setServer

public void setServer(Server server)
Specified by:
setServer in interface Handler
Overrides:
setServer in class ContextHandler

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)

getResource

public Resource getResource(String uriInContext)
                     throws MalformedURLException
Overrides:
getResource in class ContextHandler
Throws:
MalformedURLException

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class ContextHandler
Throws:
Exception

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()
Returns:
Returns the defaultsDescriptor.

getPermissions

public PermissionCollection getPermissions()
Returns:
Returns the permissions.

getSecurityHandler

public SecurityHandler getSecurityHandler()
Returns:
Returns the securityHandler.

getServerClasses

public String[] getServerClasses()
Returns:
Returns the serverClasses.

getServletHandler

public ServletHandler getServletHandler()
Returns:
Returns the servletHandler.

getSessionHandler

public SessionHandler getSessionHandler()
Returns:
Returns the sessionHandler.

getSystemClasses

public String[] getSystemClasses()
Returns:
Returns the systemClasses.

getTempDirectory

public File getTempDirectory()

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.

isParentLoaderPriority

public boolean isParentLoaderPriority()
Returns:
Returns the java2compliant.

loadConfigurations

protected void loadConfigurations()
                           throws Exception
Throws:
Exception

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)
Parameters:
defaultsDescriptor - The defaultsDescriptor to set.

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[])

Parameters:
listener -

setExtractWAR

public void setExtractWAR(boolean extractWAR)
Parameters:
extractWAR - The extractWAR to set.

setParentLoaderPriority

public void setParentLoaderPriority(boolean java2compliant)
Parameters:
java2compliant - The java2compliant to set.

setPermissions

public void setPermissions(PermissionCollection permissions)
Parameters:
permissions - The permissions to set.

setSecurityHandler

public void setSecurityHandler(SecurityHandler securityHandler)
Parameters:
sessionHandler - The sessionHandler to set.

setServerClasses

public void setServerClasses(String[] serverClasses)
Parameters:
serverClasses - The serverClasses to set.

setServletHandler

public void setServletHandler(ServletHandler servletHandler)
Parameters:
servletHandler - The servletHandler to set.

setSessionHandler

public void setSessionHandler(SessionHandler sessionHandler)
Parameters:
sessionHandler - The sessionHandler 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

startContext

protected void startContext()
                     throws Exception
Overrides:
startContext in class ContextHandler
Throws:
Exception