org.mortbay.jetty.servlet

Class WebApplicationContext

Implemented Interfaces:
Externalizable, EventProvider, HttpHandler, LifeCycle, Serializable
Known Direct Subclasses:
PlusWebAppContext

public class WebApplicationContext
extends ServletHttpContext
implements Externalizable

Standard web.xml configured HttpContext. This specialization of HttpContext uses the standardized web.xml to describe a web application and configure the handlers for the HttpContext. If a file named web-jetty.xml or jetty-web.xml is found in the WEB-INF directory it is applied to the context using the XmlConfiguration format. A single WebApplicationHandler instance is used to provide security, filter, sevlet and resource handling.
Version:
$Id: WebApplicationContext.java,v 1.136 2005/10/26 08:11:04 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
WebApplicationHandler

Nested Class Summary

static interface
WebApplicationContext.Configuration
Base Class for WebApplicationContext Configuration.

Field Summary

Fields inherited from class org.mortbay.http.HttpContext

__ErrorHandler, __fileClassPathAttr

Constructor Summary

WebApplicationContext()
Constructor.
WebApplicationContext(String webApp)
Constructor.

Method Summary

void
addEventListener(EventListener listener)
Register an EventListener
protected void
configureClassPath()
protected void
configureDefaults()
protected void
configureWebApp()
void
destroy()
Destroy a context.
protected void
doStart()
Start the Web Application.
protected void
doStop()
Stop the web application.
String[]
getConfigurationClassNames()
WebApplicationContext.Configuration[]
getConfigurations()
String
getDefaultsDescriptor()
String
getDisplayName()
String
getErrorPage(String error)
get error page URI.
boolean
getExtractWAR()
Resource
getResource(String uriInContext)
String
getResourceAlias(String alias)
Map
getResourceAliases()
ServletHandler
getServletHandler()
Get the context ServletHandler.
protected UserRealm
getUserRealm(String name)
String
getWAR()
WebApplicationHandler
getWebApplicationHandler()
Resource
getWebInf()
void
handle(String pathInContext, String pathParams, HttpRequest httpRequest, HttpResponse httpResponse)
Handler request.
protected void
initialize()
Initialize is called by the start method after the contexts classloader has been initialied, but before the defaults descriptor has been applied.
boolean
isDistributable()
boolean
isIgnoreWebJetty()
protected WebApplicationContext.Configuration[]
loadConfigurations()
void
readExternal(java.io.ObjectInput in)
String
removeErrorPage(String error)
void
removeEventListener(EventListener listener)
String
removeResourceAlias(String alias)
void
setConfigurationClassNames(String[] configurationClassNames)
void
setDefaultsDescriptor(String defaults)
Set the defaults web.xml file.
void
setDisplayName(String name)
void
setDistributable(boolean distributable)
void
setErrorPage(String error, String uriInContext)
set error page URI.
void
setExtractWAR(boolean extract)
void
setIgnoreWebJetty(boolean b)
void
setPermissions(PermissionCollection permissions)
Set the permissions to be used for this context.
void
setResourceAlias(String alias, String uri)
Set Resource Alias.
void
setWAR(String war)
String
toString()
void
writeExternal(java.io.ObjectOutput out)

Methods inherited from class org.mortbay.jetty.servlet.ServletHttpContext

addLocaleEncoding, addServlet, addServlet, checkSecurityConstraints, destroy, doStop, enterContextScope, getLocaleEncoding, getServletContext, getServletHandler, jSecurityCheck, sendError, toString

Methods inherited from class org.mortbay.http.HttpContext

addClassPath, addClassPaths, addHandler, addHandler, addPermission, addSecurityConstraint, addVirtualHost, addWelcomeFile, canonicalContextPathSpec, checkSecurityConstraints, clearSecurityConstraints, destroy, doStart, doStop, enterContextScope, flushCache, getAttribute, getAttributeNames, getAttributes, getAuthenticator, getBaseResource, getClassLoader, getClassPath, getContextPath, getEncodingByMimeType, getEncodingMap, getFileClassPath, getHandler, getHandlerIndex, getHandlers, getHosts, getHttpConnection, getHttpContext, getHttpContextName, getHttpServer, getInitParameter, getInitParameterNames, getMaxCacheSize, getMaxCachedFileSize, getMimeByExtension, getMimeMap, getName, getParentClassLoader, getPermissions, getRealm, getRealmName, getRequestLog, getRequests, getRequestsActive, getRequestsActiveMax, getResource, getResourceBase, getResourceMetaData, getResponses1xx, getResponses2xx, getResponses3xx, getResponses4xx, getResponses5xx, getServerClasses, getStatsOn, getStatsOnMs, getStopGracefully, getSystemClasses, getTempDirectory, getVirtualHosts, getWelcomeFile, getWelcomeFiles, handle, handle, initClassLoader, initialize, isClassLoaderJava2Compliant, isRedirectNullPath, leaveContextScope, loadClass, log, removeAttribute, removeHandler, removeHandler, removeVirtualHost, removeWelcomeFile, sendContextError, sendError, setAttribute, setAttributes, setAuthenticator, setBaseResource, setClassLoader, setClassLoaderJava2Compliant, setClassPath, setContextPath, setEncodingMap, setHandlers, setHosts, setHttpContextName, setInitParameter, setMaxCacheSize, setMaxCachedFileSize, setMimeMap, setMimeMapping, setParentClassLoader, setPermissions, setRealm, setRealmName, setRedirectNullPath, setRequestLog, setResourceBase, setServerClasses, setStatsOn, setStopGracefully, setSystemClasses, setTempDirectory, setTypeEncoding, setVirtualHosts, setWelcomeFiles, startHandlers, statsReset, stop, toString, toString

Methods inherited from class org.mortbay.util.Container

addComponent, addEventListener, destroy, doStart, doStop, getComponents, isStarted, isStarting, isStopping, removeComponent, removeEventListener, start, stop

Constructor Details

WebApplicationContext

public WebApplicationContext()
Constructor.

WebApplicationContext

public WebApplicationContext(String webApp)
Constructor.
Parameters:
webApp - The Web application directory or WAR file.

Method Details

addEventListener

public void addEventListener(EventListener listener)
            throws IllegalArgumentException
Register an EventListener
Specified by:
addEventListener in interface EventProvider
Overrides:
addEventListener in interface Container
Parameters:
listener -

configureClassPath

protected void configureClassPath()
            throws Exception

configureDefaults

protected void configureDefaults()
            throws Exception

configureWebApp

protected void configureWebApp()
            throws Exception

destroy

public void destroy()
Destroy a context. Destroy a context and remove it from the HttpServer. The HttpContext must be stopped before it can be destroyed.
Overrides:
destroy in interface ServletHttpContext

doStart

protected void doStart()
            throws Exception
Start the Web Application.
Overrides:
doStart in interface HttpContext

doStop

protected void doStop()
            throws Exception
Stop the web application. Handlers for resource, servlet, filter and security are removed as they are recreated and configured by any subsequent call to start().
Overrides:
doStop in interface ServletHttpContext

getConfigurationClassNames

public String[] getConfigurationClassNames()

getConfigurations

public WebApplicationContext.Configuration[] getConfigurations()

getDefaultsDescriptor

public String getDefaultsDescriptor()

getDisplayName

public String getDisplayName()

getErrorPage

public String getErrorPage(String error)
get error page URI.
Parameters:
error - A string representing an error code or a exception classname
Returns:
URI within context

getExtractWAR

public boolean getExtractWAR()

getResource

public Resource getResource(String uriInContext)
            throws IOException
Overrides:
getResource in interface HttpContext
Parameters:
Returns:

getResourceAlias

public String getResourceAlias(String alias)

getResourceAliases

public Map getResourceAliases()

getServletHandler

public ServletHandler getServletHandler()
Get the context ServletHandler. Conveniance method. If no ServletHandler exists, a new one is added to the context. This derivation of the method creates a WebApplicationHandler extension of ServletHandler.
Overrides:
getServletHandler in interface ServletHttpContext
Returns:
WebApplicationHandler

getUserRealm

protected UserRealm getUserRealm(String name)

getWAR

public String getWAR()

getWebApplicationHandler

public WebApplicationHandler getWebApplicationHandler()

getWebInf

public Resource getWebInf()
            throws IOException

handle

public void handle(String pathInContext,
                   String pathParams,
                   HttpRequest httpRequest,
                   HttpResponse httpResponse)
            throws HttpException,
                   IOException
Handler request. Call each HttpHandler until request is handled.
Specified by:
handle in interface HttpHandler
Overrides:
handle in interface HttpContext
Parameters:
pathInContext - Path in context
pathParams - Path parameters such as encoded Session ID
Throws:
HttpException -

initialize

protected void initialize()
            throws Exception
Initialize is called by the start method after the contexts classloader has been initialied, but before the defaults descriptor has been applied. The default implementation does nothing.

isDistributable

public boolean isDistributable()

isIgnoreWebJetty

public boolean isIgnoreWebJetty()

loadConfigurations

protected WebApplicationContext.Configuration[] loadConfigurations()
            throws Exception

readExternal

public void readExternal(java.io.ObjectInput in)
            throws IOException,
                   ClassNotFoundException

removeErrorPage

public String removeErrorPage(String error)

removeEventListener

public void removeEventListener(EventListener listener)
Specified by:
removeEventListener in interface EventProvider
Overrides:
removeEventListener in interface Container

removeResourceAlias

public String removeResourceAlias(String alias)

setConfigurationClassNames

public void setConfigurationClassNames(String[] configurationClassNames)

setDefaultsDescriptor

public void setDefaultsDescriptor(String defaults)
Set the defaults web.xml file. The default web.xml is used to configure all webapplications before the WEB-INF/web.xml file is applied. By default the org/mortbay/jetty/servlet/webdefault.xml resource from the org.mortbay.jetty.jar is used.
Parameters:
defaults - File, Resource, URL or null.

setDisplayName

public void setDisplayName(String name)

setDistributable

public void setDistributable(boolean distributable)

setErrorPage

public void setErrorPage(String error,
                         String uriInContext)
set error page URI.
Parameters:
error - A string representing an error code or a exception classname
uriInContext -

setExtractWAR

public void setExtractWAR(boolean extract)
Parameters:
extract - If true, a WAR is extracted to a temporary directory before being deployed.

setIgnoreWebJetty

public void setIgnoreWebJetty(boolean b)
Parameters:
b - If TRUE, web-jetty.xml and jetty-web.xml configuration files are ignored.

setPermissions

public void setPermissions(PermissionCollection permissions)
Set the permissions to be used for this context. The collection of permissions set here are used for all classes loaded by this context. This is simpler that creating a security policy file, as not all code sources may be statically known.
Overrides:
setPermissions in interface HttpContext
Parameters:
permissions -

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 -

setWAR

public void setWAR(String war)
Parameters:
war - Filename or URL of the web application directory or WAR file.

toString

public String toString()
Overrides:
toString in interface ServletHttpContext

writeExternal

public void writeExternal(java.io.ObjectOutput out)
            throws IOException

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.