public class WebAppContext extends Context
SecurityHandler
, SessionHandler
and ServletHandler
.
The handlers are configured by pluggable configuration classes, with
the default being WebXmlConfiguration
and
JettyWebXmlConfiguration
.Context.SContext
Modifier and Type | Field and Description |
---|---|
static String |
ERROR_PAGE |
static String |
WEB_DEFAULTS_XML |
_securityHandler, _servletHandler, _sessionHandler, NO_SECURITY, NO_SESSIONS, SECURITY, SESSIONS
_scontext, MANAGED_ATTRIBUTES
_string
Constructor and Description |
---|
WebAppContext() |
WebAppContext(HandlerContainer parent,
String webApp,
String contextPath) |
WebAppContext(SecurityHandler securityHandler,
SessionHandler sessionHandler,
ServletHandler servletHandler,
ErrorHandler errorHandler) |
WebAppContext(String webApp,
String contextPath) |
Modifier and Type | Method and Description |
---|---|
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.
|
Throwable |
getUnavailableException()
Get an exception that caused the webapp to be unavailable
|
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() |
addFilter, addFilter, addFilter, addServlet, addServlet, addServlet, getSecurityHandler, getServletHandler, getSessionHandler, setSecurityHandler, setServletHandler, setSessionHandler
addLocaleEncoding, clearAttributes, getAllowNullPathInfo, getAttribute, getAttributeNames, getAttributes, getBaseResource, getClassLoader, getClassPath, getConnectorNames, getContextPath, getCurrentContext, getDisplayName, getErrorHandler, getEventListeners, getHosts, getInitParameter, getInitParameterNames, getInitParams, getLocaleEncoding, getMaxFormContentSize, getMaxFormKeys, getMimeTypes, getResourceBase, getResourcePaths, getServletContext, getVirtualHosts, getWelcomeFiles, isCompactPath, isShutdown, loadClass, removeAttribute, setAllowNullPathInfo, setAttribute, setAttributes, setBaseResource, setCompactPath, setConnectorNames, setContextPath, setDisplayName, setErrorHandler, setHosts, setInitParams, setMaxFormContentSize, setMaxFormKeys, setMimeTypes, setResourceBase, setServer, setShutdown, setVirtualHosts, setWelcomeFiles
addHandler, expandChildren, getHandler, removeHandler, setHandler
expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
destroy, getServer
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public static final String WEB_DEFAULTS_XML
public static final String ERROR_PAGE
public WebAppContext()
public WebAppContext(String webApp, String contextPath)
contextPath
- The context pathwebApp
- The URL or filename of the webapp directory or war file.public WebAppContext(HandlerContainer parent, String webApp, String contextPath)
parent
- The parent HandlerContainer.contextPath
- The context pathwebApp
- The URL or filename of the webapp directory or war file.public WebAppContext(SecurityHandler securityHandler, SessionHandler sessionHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
public static ContextHandler getCurrentWebAppContext()
public static void addWebApplications(Server server, String webapps, String defaults, boolean extract, boolean java2CompliantClassLoader) throws IOException
WebAppDeployer
or ContextDeployer
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 filesjava2CompliantClassLoader
- True if java2 compliance is applied to all webapplicationsIOException
public static void addWebApplications(Server server, String webapps, String defaults, String[] configurations, boolean extract, boolean java2CompliantClassLoader) throws IOException
WebAppDeployer
or ContextDeployer
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 filesjava2CompliantClassLoader
- True if java2 compliance is applied to all webapplicationsIOException
IllegalAccessException
InstantiationException
public static void addWebApplications(HandlerContainer contexts, String webapps, String defaults, boolean extract, boolean java2CompliantClassLoader) throws IOException
WebAppDeployer
or ContextDeployer
contexts
- A HandlerContainer to which the contexts will be addedwebapps
- 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 filesjava2CompliantClassLoader
- True if java2 compliance is applied to all webapplicationsIOException
IllegalAccessException
InstantiationException
public static void addWebApplications(HandlerContainer contexts, String webapps, String defaults, String[] configurations, boolean extract, boolean java2CompliantClassLoader) throws IOException
WebAppDeployer
or ContextDeployer
contexts
- A HandlerContainer to which the contexts will be addedwebapps
- 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 filesjava2CompliantClassLoader
- True if java2 compliance is applied to all webapplicationsIOException
IllegalAccessException
InstantiationException
public Throwable getUnavailableException()
public void setResourceAlias(String alias, String uri)
alias
- uri
- public Map getResourceAliases()
public void setResourceAliases(Map map)
public void setClassLoader(ClassLoader classLoader)
setClassLoader
in class ContextHandler
classLoader
- The classLoader to set.public Resource getResource(String uriInContext) throws MalformedURLException
getResource
in class ContextHandler
MalformedURLException
public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException
Handler
handle
in interface Handler
handle
in class ContextHandler
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
IOException
ServletException
ContextHandler.handle(java.lang.String, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, int)
protected void doStart() throws Exception
doStart
in class ContextHandler
Exception
public void dumpUrl()
protected void doStop() throws Exception
doStop
in class ContextHandler
Exception
public String[] getConfigurationClasses()
public Configuration[] getConfigurations()
public String getDefaultsDescriptor()
public String getOverrideDescriptor()
public PermissionCollection getPermissions()
public String[] getServerClasses()
public String[] getSystemClasses()
public File getTempDirectory()
A. Try to use an explicit directory specifically for this webapp:
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:
public boolean isTempWorkDirectory()
public String getWar()
public Resource getWebInf() throws IOException
IOException
public boolean isDistributable()
public boolean isExtractWAR()
public boolean isCopyWebDir()
public boolean isParentLoaderPriority()
protected boolean isProtectedTarget(String target)
ContextHandler
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.isProtectedTarget
in class ContextHandler
isProtectedTarget(String)
public String toString()
toString
in class ContextHandler
protected void resolveWebApp() throws IOException
IOException
public void setConfigurationClasses(String[] configurations)
configurations
- The configuration class names. If setConfigurations is not called
these classes are used to create a configurations array.public void setConfigurations(Configuration[] configurations)
configurations
- The configurations to set.public void setDefaultsDescriptor(String defaultsDescriptor)
defaultsDescriptor
- The defaultsDescriptor to set.public void setOverrideDescriptor(String overrideDescriptor)
defaultsDescriptor
- The overrideDescritpor to set.public String getDescriptor()
public void setDescriptor(String descriptor)
descriptor
- the web.xml descriptor to use. If set to null, WEB-INF/web.xml is used if it exists.public void setDistributable(boolean distributable)
distributable
- The distributable to set.public void setEventListeners(EventListener[] eventListeners)
setEventListeners
in class ContextHandler
public void addEventListener(EventListener listener)
setEventListeners(EventListener[])
addEventListener
in class ContextHandler
listener
- public void setExtractWAR(boolean extractWAR)
extractWAR
- True if war files are extractedpublic void setCopyWebDir(boolean copy)
copy
- True if the webdir is copied (to allow hot replacement of jars)public void setParentLoaderPriority(boolean java2compliant)
java2compliant
- The java2compliant to set.public void setPermissions(PermissionCollection permissions)
permissions
- The permissions to set.public void setServerClasses(String[] serverClasses)
serverClasses
- The serverClasses to set.public void setSystemClasses(String[] systemClasses)
systemClasses
- The systemClasses to set.public void setTempDirectory(File dir)
dir
- Writable temporary directory.public void setWar(String war)
war
- The war to set as a file name or URLpublic String getExtraClasspath()
public void setExtraClasspath(String extraClasspath)
extraClasspath
- Comma or semicolon separated path of filenames or URLs
pointing to directories or jar files. Directories should end
with '/'.public boolean isLogUrlOnStart()
public void setLogUrlOnStart(boolean logOnStart)
logOnStart
- whether or not the log message is createdprotected void startContext() throws Exception
startContext
in class Context
Exception
ContextHandler.startContext()
Copyright © 2009 Mortbay Consulting Pty. Ltd. All Rights Reserved.