org.mortbay.jetty.servlet
Class WebApplicationContext

java.lang.Object
  extended byorg.mortbay.http.ResourceCache
      extended byorg.mortbay.http.HttpContext
          extended byorg.mortbay.jetty.servlet.ServletHttpContext
              extended byorg.mortbay.jetty.servlet.WebApplicationContext
All Implemented Interfaces:
java.io.Externalizable, HttpHandler, LifeCycle, java.io.Serializable
Direct Known Subclasses:
PlusWebAppContext

public class WebApplicationContext
extends ServletHttpContext
implements java.io.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.121 2004/06/04 21:37:20 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
WebApplicationHandler, Serialized Form

Nested Class Summary
static class WebApplicationContext.Configuration
          Base Class for WebApplicationContext Configuration.
 
Nested classes inherited from class org.mortbay.http.ResourceCache
ResourceCache.ResourceMetaData
 
Field Summary
 
Fields inherited from class org.mortbay.http.HttpContext
__ErrorHandler, __fileClassPathAttr
 
Constructor Summary
WebApplicationContext()
          Constructor.
WebApplicationContext(java.lang.String webApp)
          Constructor.
 
Method Summary
 void addEventListener(java.util.EventListener listener)
           
 WebApplicationContext.Configuration getConfiguration()
           
 java.lang.String getDefaultsDescriptor()
           
 java.lang.String getDisplayName()
           
 java.lang.String getErrorPage(java.lang.String error)
          get error page URI.
 boolean getExtractWAR()
           
 Resource getResource(java.lang.String uriInContext)
          Get a resource from the context.
 java.lang.String getResourceAlias(java.lang.String alias)
           
 ServletHandler getServletHandler()
          Get the context ServletHandler.
 java.lang.String getWAR()
           
 WebApplicationHandler getWebApplicationHandler()
           
 Resource getWebInf()
           
 void handle(java.lang.String pathInContext, java.lang.String pathParams, HttpRequest httpRequest, HttpResponse httpResponse)
          Handler request.
 boolean isDistributable()
           
 boolean isIgnoreWebJetty()
           
 void readExternal(java.io.ObjectInput in)
           
 void removeAttribute(java.lang.String name)
           
 java.lang.String removeErrorPage(java.lang.String error)
           
 void removeEventListener(java.util.EventListener listener)
           
 java.lang.String removeResourceAlias(java.lang.String alias)
           
 void setAttribute(java.lang.String name, java.lang.Object value)
          Set a context attribute.
 void setConfiguration(WebApplicationContext.Configuration configuration)
           
 void setDefaultsDescriptor(java.lang.String defaults)
          Set the defaults web.xml file.
 void setDisplayName(java.lang.String name)
           
 void setDistributable(boolean distributable)
           
 void setErrorPage(java.lang.String error, java.lang.String uriInContext)
          set error page URI.
 void setExtractWAR(boolean extract)
           
 void setIgnoreWebJetty(boolean b)
           
 void setPermissions(java.security.PermissionCollection permissions)
          Set the permissions to be used for this context.
 void setResourceAlias(java.lang.String alias, java.lang.String uri)
          Set Resource Alias.
 void setWAR(java.lang.String war)
           
 void start()
          Start the Web Application.
 void stop()
          Stop the web application.
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.mortbay.jetty.servlet.ServletHttpContext
addLocaleEncoding, addServlet, addServlet, checkSecurityConstraints, getLocaleEncoding, getServletContext, sendError
 
Methods inherited from class org.mortbay.http.HttpContext
addClassPath, addClassPaths, addHandler, addHandler, addPermission, addSecurityConstraint, addVirtualHost, addWelcomeFile, canonicalContextPathSpec, clearSecurityConstraints, destroy, enterContextScope, flushCache, getAttribute, getAttributeNames, getAttributes, getAuthenticator, getClassLoader, getClassPath, getContextPath, getFileClassPath, getHandler, getHandlerIndex, getHandlers, getHosts, getHttpConnection, getHttpContext, getHttpContextName, getHttpServer, getInitParameter, getInitParameterNames, getName, getParentClassLoader, getPermissions, getRealm, getRealmName, getRequestLog, getRequests, getRequestsActive, getRequestsActiveMax, getResponses1xx, getResponses2xx, getResponses3xx, getResponses4xx, getResponses5xx, getStatsOn, getStatsOnMs, getTempDirectory, getVirtualHosts, getWelcomeFile, getWelcomeFiles, handle, initialize, isClassLoaderJava2Compliant, isRedirectNullPath, isStarted, leaveContextScope, loadClass, log, removeHandler, removeHandler, removeVirtualHost, removeWelcomeFile, sendContextError, setAttributes, setAuthenticator, setClassLoader, setClassLoaderJava2Compliant, setClassPath, setContextPath, setHandlers, setHosts, setHttpContextName, setInitParameter, setParentClassLoader, setRealm, setRealmName, setRedirectNullPath, setRequestLog, setStatsOn, setTempDirectory, setVirtualHosts, setWelcomeFiles, statsReset, stop, toString
 
Methods inherited from class org.mortbay.http.ResourceCache
getBaseResource, getEncodingByMimeType, getEncodingMap, getMaxCachedFileSize, getMaxCacheSize, getMimeByExtension, getMimeMap, getResourceBase, getResourceMetaData, setBaseResource, setEncodingMap, setMaxCachedFileSize, setMaxCacheSize, setMimeMap, setMimeMapping, setResourceBase, setTypeEncoding
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

WebApplicationContext

public WebApplicationContext()
Constructor.


WebApplicationContext

public WebApplicationContext(java.lang.String webApp)
Constructor.

Parameters:
webApp - The Web application directory or WAR file.
Method Detail

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

setConfiguration

public void setConfiguration(WebApplicationContext.Configuration configuration)

getConfiguration

public WebApplicationContext.Configuration getConfiguration()

setWAR

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

getWAR

public java.lang.String getWAR()

getWebApplicationHandler

public WebApplicationHandler getWebApplicationHandler()

getWebInf

public Resource getWebInf()
                   throws java.io.IOException
Throws:
java.io.IOException

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 class ServletHttpContext
Returns:
WebApplicationHandler

setPermissions

public void setPermissions(java.security.PermissionCollection permissions)
Description copied from class: HttpContext
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 class HttpContext
Parameters:
permissions -

isIgnoreWebJetty

public boolean isIgnoreWebJetty()

setIgnoreWebJetty

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

isDistributable

public boolean isDistributable()

setDistributable

public void setDistributable(boolean distributable)

start

public void start()
           throws java.lang.Exception
Start the Web Application.

Specified by:
start in interface LifeCycle
Overrides:
start in class HttpContext
Throws:
java.io.IOException
java.lang.Exception

stop

public void stop()
          throws java.lang.InterruptedException
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().

Specified by:
stop in interface LifeCycle
Overrides:
stop in class ServletHttpContext
Throws:
java.lang.InterruptedException

handle

public void handle(java.lang.String pathInContext,
                   java.lang.String pathParams,
                   HttpRequest httpRequest,
                   HttpResponse httpResponse)
            throws HttpException,
                   java.io.IOException
Description copied from class: HttpContext
Handler request. Call each HttpHandler until request is handled.

Specified by:
handle in interface HttpHandler
Overrides:
handle in class HttpContext
Parameters:
pathInContext - Path in context
pathParams - Path parameters such as encoded Session ID
httpRequest -
httpResponse -
Returns:
True if the request has been handled.
Throws:
HttpException
java.io.IOException

addEventListener

public void addEventListener(java.util.EventListener listener)
                      throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

removeEventListener

public void removeEventListener(java.util.EventListener listener)

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object value)
Description copied from class: HttpContext
Set a context attribute.

Overrides:
setAttribute in class HttpContext
Parameters:
name - attribute name
value - attribute value

removeAttribute

public void removeAttribute(java.lang.String name)
Overrides:
removeAttribute in class HttpContext
Parameters:
name - attribute name

getDisplayName

public java.lang.String getDisplayName()

setDisplayName

public void setDisplayName(java.lang.String name)

setDefaultsDescriptor

public void setDefaultsDescriptor(java.lang.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.

getDefaultsDescriptor

public java.lang.String getDefaultsDescriptor()

setExtractWAR

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

getExtractWAR

public boolean getExtractWAR()

toString

public java.lang.String toString()
Overrides:
toString in class ServletHttpContext

setResourceAlias

public void setResourceAlias(java.lang.String alias,
                             java.lang.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 -

getResourceAlias

public java.lang.String getResourceAlias(java.lang.String alias)

removeResourceAlias

public java.lang.String removeResourceAlias(java.lang.String alias)

getResource

public Resource getResource(java.lang.String uriInContext)
                     throws java.io.IOException
Description copied from class: ResourceCache
Get a resource from the context. Cached Resources are returned if the resource fits within the LRU cache. Directories may have CachedResources returned, but the caller must use the CachedResource.setCachedData method to set the formatted directory content.

Overrides:
getResource in class ResourceCache
Parameters:
uriInContext -
Returns:
Resource
Throws:
java.io.IOException

setErrorPage

public void setErrorPage(java.lang.String error,
                         java.lang.String uriInContext)
set error page URI.

Parameters:
error - A string representing an error code or a exception classname
uriInContext -

getErrorPage

public java.lang.String getErrorPage(java.lang.String error)
get error page URI.

Parameters:
error - A string representing an error code or a exception classname
Returns:
URI within context

removeErrorPage

public java.lang.String removeErrorPage(java.lang.String error)


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