Top Description Fields Constructors Methods
org.mortbay.jetty.webapp

public Class WebAppContext

extends Context
Class Inheritance
Imports
java.io.File, .IOException, java.net.MalformedURLException, java.security.PermissionCollection, java.util.EventListener, .HashMap, .Map, javax.servlet.ServletException, javax.servlet.http.HttpServletRequest, .HttpServletResponse, .HttpSessionActivationListener, .HttpSessionAttributeListener, .HttpSessionBindingListener, .HttpSessionListener, org.mortbay.jetty.Connector, .HandlerContainer, org.mortbay.jetty.handler.ContextHandler, .ErrorHandler, org.mortbay.jetty.security.ConstraintsSecurityHandler, org.mortbay.jetty.servlet.Context, .ErrorPageErrorHandler, .ServletHandler, .SessionHandler, org.mortbay.log.Log, org.mortbay.resource.JarResource, .Resource, org.mortbay.util.IO, .LazyList, .Loader, .StringUtil, .URIUtil

Web Application Context Handler. The WebAppContext handler is an extension of ContextHandler that coordinates the construction and configuration of nested handlers: org.mortbay.jetty.security.ConstraintsSecurityHandler, org.mortbay.jetty.servlet.SessionHandler and org.mortbay.jetty.servlet.ServletHandler. The handlers are configured by pluggable configuration classes, with the default being org.mortbay.jetty.webapp.WebXmlConfiguration and org.mortbay.jetty.webapp.JettyWebXmlConfiguration.
Author
gregw

Field Summary

Modifier and TypeField and Description
private static String[]
private String[]
private Configuration[]
private boolean
private String
private String
private boolean
private String
private boolean
private boolean
private boolean
private String
private transient boolean
private boolean
private PermissionCollection
private transient Map<K, V>
private String[]
private String[]
private File
private transient boolean
private Throwable
private String
public static final String
public static final String
Inherited from org.mortbay.jetty.servlet.Context:
_securityHandler_servletHandler_sessionHandlerNO_SECURITYNO_SESSIONSSECURITYSESSIONS

Constructor Summary

AccessConstructor and Description
public
public
WebAppContext(String
The URL or filename of the webapp directory or war file.
webApp
,
String
The context path
contextPath
)

public
WebAppContext(HandlerContainer
The parent HandlerContainer.
parent
,
String
The URL or filename of the webapp directory or war file.
webApp
,
String
The context path
contextPath
)

public
WebAppContext(ConstraintsSecurityHandler securityHandler, SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler)

Method Summary

Modifier and TypeMethod and Description
public void
protected void
protected void
public void
private String
getCanonicalNameForWebAppTmpDir()

Create a canonical name for a webapp tmp directory.

public String[]

Returns:

Returns the configurations.
getConfigurationClasses
()

public Configuration[]

Returns:

Returns the configurations.
getConfigurations
()

public ConstraintsSecurityHandler
public static ContextHandler
public String

Returns:

Returns the defaultsDescriptor.
getDefaultsDescriptor
()

The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml

public String

Returns:

the web.xml descriptor to use. If set to null, WEB-INF/web.xml is used if it exists.
getDescriptor
()

public String

Returns:

Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
getExtraClasspath
()

public String

Returns:

Returns the Override Descriptor.
getOverrideDescriptor
()

The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml

public PermissionCollection

Returns:

Returns the permissions.
getPermissions
()

public Resource
public String
public Map<K, V>
public String[]

Returns:

Returns the serverClasses.
getServerClasses
()

public String[]

Returns:

Returns the systemClasses.
getSystemClasses
()

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.

public Throwable

Returns:

A throwable if the webapp is unavailable or null
getUnavailableException
()

Get an exception that caused the webapp to be unavailable

public String

Returns:

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

public Resource
public void
handle(String
The target of the request - either a URI or a name.
target
,
HttpServletRequest
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.
request
,
HttpServletResponse
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.
response
,
int
The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR
dispatch
)

Overrides org.mortbay.jetty.handler.ContextHandler.handle.

Implements org.mortbay.jetty.Handler.handle.

Handle a request.
public boolean

Returns:

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

public boolean

Returns:

Returns the distributable.
isDistributable
()

public boolean

Returns:

Returns the extractWAR.
isExtractWAR
()

public boolean
public boolean

Returns:

Returns the java2compliant.
isParentLoaderPriority
()

protected boolean
public boolean
public boolean
public boolean
isTempWorkDirectory()

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

protected void
public String
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).

public void
public void
setConfigurationClasses(String[]
The configuration class names. If setConfigurations is not called these classes are used to create a configurations array.
configurations
)

public void
setConfigurations(Configuration[]
The configurations to set.
configurations
)

public void
setCopyWebDir(boolean
True if the webdir is copied (to allow hot replacement of jars)
copy
)

public void
setDefaultsDescriptor(String
The defaultsDescriptor to set.
defaultsDescriptor
)

The default descriptor is a web.xml format file that is applied to the context before the standard WEB-INF/web.xml

public void
setDescriptor(String
the web.xml descriptor to use. If set to null, WEB-INF/web.xml is used if it exists.
descriptor
)

public void
setDisplayName(String
The servletContextName to set.
servletContextName
)

Overrides org.mortbay.jetty.handler.ContextHandler.setDisplayName.

public void
setDistributable(boolean
The distributable to set.
distributable
)

public void
setEventListeners(EventListener[] eventListeners)

Overrides org.mortbay.jetty.handler.ContextHandler.setEventListeners.

Set the context event listeners.
public void
setExtraClasspath(String
Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.
extraClasspath
)

public void
setExtractWAR(boolean
True if war files are extracted
extractWAR
)

public void
setLogUrlOnStart(boolean
whether or not the log message is created
logOnStart
)

Sets whether or not the web app name and URL is logged on startup

public void
setOverrideDescriptor(String
The overrideDescritpor to set.
overrideDescriptor
)

The override descriptor is a web.xml format file that is applied to the context after the standard WEB-INF/web.xml

public void
setParentLoaderPriority(boolean
The java2compliant to set.
java2compliant
)

public void
setPermissions(PermissionCollection
The permissions to set.
permissions
)

public void
setResourceAlias(String alias, String uri)

Set Resource Alias.

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

Set the server classes patterns.

public void
setSystemClasses(String[]
The systemClasses to set.
systemClasses
)

Set the system classes patterns.

public void
setTempDirectory(File
Writable temporary directory.
dir
)

Set temporary directory for context.

public void
setWar(String
The war to set as a file name or URL
war
)

protected void
public String
toString()

Overrides org.mortbay.jetty.handler.ContextHandler.toString.

Returns a string representation of the object.
Inherited from org.mortbay.jetty.servlet.Context:
addFilteraddFilteraddFilteraddServletaddServletaddServletgetSecurityHandlergetServletHandlergetSessionHandlersetSecurityHandlersetServletHandlersetSessionHandler

Field Detail

__dftConfigurationClassesback to summary
private static String[] __dftConfigurationClasses
_configurationClassesback to summary
private String[] _configurationClasses
_configurationsback to summary
private Configuration[] _configurations
_copyDirback to summary
private boolean _copyDir
_defaultsDescriptorback to summary
private String _defaultsDescriptor
_descriptorback to summary
private String _descriptor
_distributableback to summary
private boolean _distributable
_extraClasspathback to summary
private String _extraClasspath
_extractWARback to summary
private boolean _extractWAR
_isExistingTmpDirback to summary
private boolean _isExistingTmpDir
_logUrlOnStartback to summary
private boolean _logUrlOnStart
_overrideDescriptorback to summary
private String _overrideDescriptor
_ownClassLoaderback to summary
private transient boolean _ownClassLoader
_parentLoaderPriorityback to summary
private boolean _parentLoaderPriority
_permissionsback to summary
private PermissionCollection _permissions
_resourceAliasesback to summary
private transient Map<K, V> _resourceAliases
_serverClassesback to summary
private String[] _serverClasses
_systemClassesback to summary
private String[] _systemClasses
_tmpDirback to summary
private File _tmpDir
_unavailableback to summary
private transient boolean _unavailable
_unavailableExceptionback to summary
private Throwable _unavailableException
_warback to summary
private String _war
ERROR_PAGEback to summary
public static final String ERROR_PAGE
WEB_DEFAULTS_XMLback to summary
public static final String WEB_DEFAULTS_XML

Constructor Detail

WebAppContextback to summary
public WebAppContext()
WebAppContextback to summary
public WebAppContext(String webApp, String contextPath)
Parameters
webApp:String

The URL or filename of the webapp directory or war file.

contextPath:String

The context path

WebAppContextback to summary
public WebAppContext(HandlerContainer parent, String webApp, String contextPath)
Parameters
parent:HandlerContainer

The parent HandlerContainer.

webApp:String

The URL or filename of the webapp directory or war file.

contextPath:String

The context path

WebAppContextback to summary
public WebAppContext(ConstraintsSecurityHandler securityHandler, SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler)

Method Detail

addEventListenerback to summary
public void addEventListener(EventListener listener)

Overrides org.mortbay.jetty.handler.ContextHandler.addEventListener.

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

doStartback to summary
protected void doStart() throws Exception

Overrides org.mortbay.jetty.handler.ContextHandler.doStart.

doStopback to summary
protected void doStop() throws Exception

Overrides org.mortbay.jetty.handler.ContextHandler.doStop.

dumpUrlback to summary
public void dumpUrl()
getCanonicalNameForWebAppTmpDirback to summary
private String getCanonicalNameForWebAppTmpDir()

Create a canonical name for a webapp tmp directory. The form of the name is: "Jetty_"+host+"_"+port+"__"+resourceBase+"_"+context+"_"+virtualhost+base36 hashcode of whole string host and port uniquely identify the server context and virtual host uniquely identify the webapp

getConfigurationClassesback to summary
public String[] getConfigurationClasses()
Returns:String[]

Returns the configurations.

getConfigurationsback to summary
public Configuration[] getConfigurations()
Returns:Configuration[]

Returns the configurations.

getConstraintsSecurityHandlerback to summary
public ConstraintsSecurityHandler getConstraintsSecurityHandler()
getCurrentWebAppContextback to summary
public static ContextHandler getCurrentWebAppContext()
getDefaultsDescriptorback to summary
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:String

Returns the defaultsDescriptor.

getDescriptorback to summary
public String getDescriptor()
Returns:String

the web.xml descriptor to use. If set to null, WEB-INF/web.xml is used if it exists.

getExtraClasspathback to summary
public String getExtraClasspath()
Returns:String

Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.

getOverrideDescriptorback to summary
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:String

Returns the Override Descriptor.

getPermissionsback to summary
public PermissionCollection getPermissions()
Returns:PermissionCollection

Returns the permissions.

getResourceback to summary
public Resource getResource(String uriInContext) throws MalformedURLException

Overrides org.mortbay.jetty.handler.ContextHandler.getResource.

getResourceAliasback to summary
public String getResourceAlias(String alias)
getResourceAliasesback to summary
public Map<K, V> getResourceAliases()
getServerClassesback to summary
public String[] getServerClasses()
Returns:String[]

Returns the serverClasses.

See Also
setServerClasses(String[])
getSystemClassesback to summary
public String[] getSystemClasses()
Returns:String[]

Returns the systemClasses.

See Also
setSystemClasses(String[])
getTempDirectoryback to summary
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.
getUnavailableExceptionback to summary
public Throwable getUnavailableException()

Get an exception that caused the webapp to be unavailable

Returns:Throwable

A throwable if the webapp is unavailable or null

getWarback to summary
public String getWar()
Returns:String

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

getWebInfback to summary
public Resource getWebInf() throws IOException
handleback to summary
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException

Overrides org.mortbay.jetty.handler.ContextHandler.handle.

Implements org.mortbay.jetty.Handler.handle.

Doc from org.mortbay.jetty.Handler.handle.

Handle a request.

Parameters
target:String

The target of the request - either a URI or a name.

request:HttpServletRequest

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:HttpServletResponse

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:int

The dispatch mode: REQUEST, FORWARD, INCLUDE, ERROR

See Also
org.mortbay.jetty.handler.ContextHandler#handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
isCopyWebDirback to summary
public boolean isCopyWebDir()
Returns:boolean

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

isDistributableback to summary
public boolean isDistributable()
Returns:boolean

Returns the distributable.

isExtractWARback to summary
public boolean isExtractWAR()
Returns:boolean

Returns the extractWAR.

isLogUrlOnStartback to summary
public boolean isLogUrlOnStart()
isParentLoaderPriorityback to summary
public boolean isParentLoaderPriority()
Returns:boolean

Returns the java2compliant.

isProtectedTargetback to summary
protected boolean isProtectedTarget(String target)

Overrides org.mortbay.jetty.handler.ContextHandler.isProtectedTarget.

Doc from org.mortbay.jetty.handler.ContextHandler.isProtectedTarget.

Check the target. Called by 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.

isServerClassback to summary
public boolean isServerClass(String name)
isSystemClassback to summary
public boolean isSystemClass(String name)
isTempWorkDirectoryback to summary
public boolean isTempWorkDirectory()

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

loadConfigurationsback to summary
protected void loadConfigurations() throws Exception
removeResourceAliasback to summary
public String removeResourceAlias(String alias)
resolveWebAppback to summary
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).

setClassLoaderback to summary
public void setClassLoader(ClassLoader classLoader)

Overrides org.mortbay.jetty.handler.ContextHandler.setClassLoader.

Parameters
classLoader:ClassLoader

Doc from org.mortbay.jetty.handler.ContextHandler.setClassLoader.

The classLoader to set.

setConfigurationClassesback to summary
public void setConfigurationClasses(String[] configurations)
Parameters
configurations:String[]

The configuration class names. If setConfigurations is not called these classes are used to create a configurations array.

setConfigurationsback to summary
public void setConfigurations(Configuration[] configurations)
Parameters
configurations:Configuration[]

The configurations to set.

setCopyWebDirback to summary
public void setCopyWebDir(boolean copy)
Parameters
copy:boolean

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

setDefaultsDescriptorback to summary
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:String

The defaultsDescriptor to set.

setDescriptorback to summary
public void setDescriptor(String descriptor)
Parameters
descriptor:String

the web.xml descriptor to use. If set to null, WEB-INF/web.xml is used if it exists.

setDisplayNameback to summary
public void setDisplayName(String servletContextName)

Overrides org.mortbay.jetty.handler.ContextHandler.setDisplayName.

Parameters
servletContextName:String

The servletContextName to set.

setDistributableback to summary
public void setDistributable(boolean distributable)
Parameters
distributable:boolean

The distributable to set.

setEventListenersback to summary
public void setEventListeners(EventListener[] eventListeners)

Overrides org.mortbay.jetty.handler.ContextHandler.setEventListeners.

Doc from org.mortbay.jetty.handler.ContextHandler.setEventListeners.

Set the context event listeners.

setExtraClasspathback to summary
public void setExtraClasspath(String extraClasspath)
Parameters
extraClasspath:String

Comma or semicolon separated path of filenames or URLs pointing to directories or jar files. Directories should end with '/'.

setExtractWARback to summary
public void setExtractWAR(boolean extractWAR)
Parameters
extractWAR:boolean

True if war files are extracted

setLogUrlOnStartback to summary
public void setLogUrlOnStart(boolean logOnStart)

Sets whether or not the web app name and URL is logged on startup

Parameters
logOnStart:boolean

whether or not the log message is created

setOverrideDescriptorback to summary
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:String

The overrideDescritpor to set.

setParentLoaderPriorityback to summary
public void setParentLoaderPriority(boolean java2compliant)
Parameters
java2compliant:boolean

The java2compliant to set.

setPermissionsback to summary
public void setPermissions(PermissionCollection permissions)
Parameters
permissions:PermissionCollection

The permissions to set.

setResourceAliasback to summary
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.

setResourceAliasesback to summary
public void setResourceAliases(Map<K, V> map)
setServerClassesback to summary
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 class pattern is a string of one of the forms:

org.package.Classname
Match a specific class
org.package.
Match a specific package hierarchy
-org.package.Classname
Exclude a specific class
-org.package.
Exclude a specific package hierarchy
Parameters
serverClasses:String[]

The serverClasses to set.

setSystemClassesback to summary
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 class pattern is a string of one of the forms:

org.package.Classname
Match a specific class
org.package.
Match a specific package hierarchy
-org.package.Classname
Exclude a specific class
-org.package.
Exclude a specific package hierarchy
Parameters
systemClasses:String[]

The systemClasses to set.

setTempDirectoryback to summary
public void setTempDirectory(File dir)

Set temporary directory for context. The javax.servlet.context.tempdir attribute is also set.

Parameters
dir:File

Writable temporary directory.

setWarback to summary
public void setWar(String war)
Parameters
war:String

The war to set as a file name or URL

startContextback to summary
protected void startContext() throws Exception

Overrides org.mortbay.jetty.servlet.Context.startContext.

toStringback to summary
public String toString()

Overrides org.mortbay.jetty.handler.ContextHandler.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.