org.mortbay.jetty.servlet
Class WebApplicationContext

java.lang.Object
  extended by org.mortbay.util.Container
      extended by org.mortbay.http.HttpContext
          extended by org.mortbay.jetty.servlet.ServletHttpContext
              extended by org.mortbay.jetty.servlet.WebApplicationContext
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, HttpHandler, EventProvider, LifeCycle
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.136 2005/10/26 08:11:04 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
WebApplicationHandler, Serialized Form

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(java.lang.String webApp)
          Constructor.
 
Method Summary
 void addEventListener(java.util.EventListener listener)
          Add a server event listener.
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.
 java.lang.String[] getConfigurationClassNames()
           
 WebApplicationContext.Configuration[] getConfigurations()
           
 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)
           
 java.lang.String getResourceAlias(java.lang.String alias)
           
 java.util.Map getResourceAliases()
           
 ServletHandler getServletHandler()
          Get the context ServletHandler.
protected  UserRealm getUserRealm(java.lang.String name)
           
 java.lang.String getWAR()
           
 WebApplicationHandler getWebApplicationHandler()
           
 Resource getWebInf()
           
 void handle(java.lang.String pathInContext, java.lang.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)
           
 java.lang.String removeErrorPage(java.lang.String error)
           
 void removeEventListener(java.util.EventListener listener)
           
 java.lang.String removeResourceAlias(java.lang.String alias)
           
 void setConfigurationClassNames(java.lang.String[] configurationClassNames)
           
 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)
           
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class org.mortbay.jetty.servlet.ServletHttpContext
addLocaleEncoding, addServlet, addServlet, checkSecurityConstraints, enterContextScope, getLocaleEncoding, getServletContext, jSecurityCheck, sendError
 
Methods inherited from class org.mortbay.http.HttpContext
addClassPath, addClassPaths, addHandler, addHandler, addPermission, addSecurityConstraint, addVirtualHost, addWelcomeFile, canonicalContextPathSpec, clearSecurityConstraints, flushCache, getAttribute, getAttributeNames, getAttributes, getAuthenticator, getBaseResource, getClassLoader, getClassPath, getContextPath, getEncodingByMimeType, getEncodingMap, getFileClassPath, getHandler, getHandlerIndex, getHandlers, getHosts, getHttpConnection, getHttpContext, getHttpContextName, getHttpServer, getInitParameter, getInitParameterNames, getMaxCachedFileSize, getMaxCacheSize, getMimeByExtension, getMimeMap, getName, getParentClassLoader, getPermissions, getRealm, getRealmName, getRequestLog, getRequests, getRequestsActive, getRequestsActiveMax, getResourceBase, getResourceMetaData, getResponses1xx, getResponses2xx, getResponses3xx, getResponses4xx, getResponses5xx, getServerClasses, getStatsOn, getStatsOnMs, getStopGracefully, getSystemClasses, getTempDirectory, getVirtualHosts, getWelcomeFile, getWelcomeFiles, handle, initClassLoader, initialize, isClassLoaderJava2Compliant, isRedirectNullPath, leaveContextScope, loadClass, log, removeAttribute, removeHandler, removeHandler, removeVirtualHost, removeWelcomeFile, sendContextError, setAttribute, setAttributes, setAuthenticator, setBaseResource, setClassLoader, setClassLoaderJava2Compliant, setClassPath, setContextPath, setEncodingMap, setHandlers, setHosts, setHttpContextName, setInitParameter, setMaxCachedFileSize, setMaxCacheSize, setMimeMap, setMimeMapping, setParentClassLoader, setRealm, setRealmName, setRedirectNullPath, setRequestLog, setResourceBase, setServerClasses, setStatsOn, setStopGracefully, setSystemClasses, setTempDirectory, setTypeEncoding, setVirtualHosts, setWelcomeFiles, startHandlers, statsReset, stop, toString
 
Methods inherited from class org.mortbay.util.Container
addComponent, getComponents, isFailed, isStarted, isStarting, isStopping, removeComponent, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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

setConfigurationClassNames

public void setConfigurationClassNames(java.lang.String[] configurationClassNames)

getConfigurationClassNames

public java.lang.String[] getConfigurationClassNames()

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

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)

getConfigurations

public WebApplicationContext.Configuration[] getConfigurations()

loadConfigurations

protected WebApplicationContext.Configuration[] loadConfigurations()
                                                            throws java.lang.Exception
Throws:
java.lang.Exception

configureClassPath

protected void configureClassPath()
                           throws java.lang.Exception
Throws:
java.lang.Exception

configureDefaults

protected void configureDefaults()
                          throws java.lang.Exception
Throws:
java.lang.Exception

configureWebApp

protected void configureWebApp()
                        throws java.lang.Exception
Throws:
java.lang.Exception

doStart

protected void doStart()
                throws java.lang.Exception
Start the Web Application.

Overrides:
doStart in class HttpContext
Throws:
java.io.IOException
java.lang.Exception

doStop

protected void doStop()
               throws java.lang.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 class ServletHttpContext
Throws:
java.lang.InterruptedException
java.lang.Exception

destroy

public void destroy()
Description copied from class: HttpContext
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 class ServletHttpContext

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 - The HttpRequest request
httpResponse - The HttpResponse response
Throws:
HttpException
java.io.IOException

addEventListener

public void addEventListener(java.util.EventListener listener)
                      throws java.lang.IllegalArgumentException
Description copied from class: Container
Add a server event listener.

Specified by:
addEventListener in interface EventProvider
Overrides:
addEventListener in class Container
Parameters:
listener - ComponentEventListener or LifeCycleEventListener
Throws:
java.lang.IllegalArgumentException - If the EventListener type is not supported.

removeEventListener

public void removeEventListener(java.util.EventListener listener)
Specified by:
removeEventListener in interface EventProvider
Overrides:
removeEventListener in class Container

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()

initialize

protected void initialize()
                   throws java.lang.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.

Throws:
java.lang.Exception - if an error occurs

getUserRealm

protected UserRealm getUserRealm(java.lang.String name)

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 -

getResourceAliases

public java.util.Map getResourceAliases()

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
Overrides:
getResource in class HttpContext
Returns:
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.