org.apache.tomcat.core
Class ContextManager

java.lang.Object
  |
  +--org.apache.tomcat.core.ContextManager

public class ContextManager
extends java.lang.Object

ContextManager is the entry point and "controler" of the servlet execution. It maintains a list of WebApplications and a list of global event interceptors that are set up to handle the actual execution. The ContextManager is a helper that will direct the request processing flow from its arrival from the server/protocl adapter ( in service() ). It is also responsible for controlling the request processing steps, from request parsing and mapping, auth, autorization, pre/post service, actual invocation and logging. It will also store properties that are global to the servlet container - like root directory, install dir, work dir.

Author:
James Duncan Davidson [duncan@eng.sun.com], James Todd [gonzo@eng.sun.com], Harish Prabandham, costin@eng.sun.com, Hans Bergsten [hans@gefionsoftware.com]

Field Summary
static int ACC_INIT_END
           
static int ACC_INIT_START
           
static int ACCOUNTS
           
static int CONTAINER_NOTE
           
static java.lang.String DEFAULT_HOSTNAME
           
static int DEFAULT_PORT
           
static java.lang.String DEFAULT_WORK_DIR
          Default work dir, relative to home
static int HANDLER_NOTE
           
static int MAX_NOTES
          Maximum number of notes supported
static int REQ_RE_NOTE
           
static int REQUEST_NOTE
           
static int RESERVED
           
static int SERVER_NOTE
           
 
Constructor Summary
ContextManager()
          Construct a new ContextManager instance with default values.
 
Method Summary
 void addContainer(Container container)
          Notify interceptors that a new container was added.
 void addContext(Context ctx)
          Adds a new Context to the set managed by this ContextManager.
 void addContextInterceptor(ContextInterceptor ci)
           
 void addLogger(org.apache.tomcat.logging.Logger l)
           
 void addRequestInterceptor(RequestInterceptor ri)
           
 void addServerConnector(ServerConnector con)
          Add the specified server connector to the those attached to this server.
 Request createRequest(Context ctx, java.lang.String urlPath)
          Create a new sub-request in a given context, set the context "hint" This is a particular case of sub-request that can't get out of a context ( and we know the context before - so no need to compute it again) Note that session and all stuff will still be computed.
 Request createRequest(java.lang.String urlPath)
          Create a new sub-request, deal with query string
 int doAuthenticate(Request req, Response res)
          Call all authentication callbacks.
 int doAuthorize(Request req, Response res, java.lang.String[] roles)
          Call all authorization callbacks.
 void doLog(java.lang.String msg)
           
 void doLog(java.lang.String msg, java.lang.Throwable t)
           
 void doLog(java.lang.String msg, java.lang.Throwable t, int level)
           
 void doPostServletDestroy(Context ctx, ServletWrapper sw)
           
 void doPostServletInit(Context ctx, ServletWrapper sw)
           
 void doPreServletDestroy(Context ctx, ServletWrapper sw)
           
 void doPreServletInit(Context ctx, ServletWrapper sw)
           
 java.io.File getAbsolute(java.io.File f)
          Convert a relative name to absolute by using the "home" property
 long getAccount(int pos)
           
 java.util.Enumeration getConnectors()
           
 Context getContext(java.lang.String name)
          Deprecated. Use an external iterator to find the context that matches your conditions.
 ContextInterceptor[] getContextInterceptors()
          Return the context interceptors as an array.
 java.util.Enumeration getContextNames()
          Deprecated. Path is not "unique key".
 java.util.Enumeration getContexts()
          Return the list of contexts managed by this server
 int getDebug()
           
 ServletWrapper getHandlerForPath(Context ctx, java.lang.String path)
           
 java.lang.String getHome()
          The home of the tomcat instance - you can have multiple users running tomcat, with a shared install directory.
 java.lang.String getHostName()
          Deprecated.  
 java.lang.String getInstallDir()
          Get installation directory, where libraries and default files are located.
 java.lang.Object getNote(int pos)
           
 int getNoteId(int noteType, java.lang.String name)
          Create a new note id.
 java.lang.String getNoteName(int noteType, int noteId)
           
 java.lang.Object getPermissions()
          Get the default Security Permissions for this server
 int getPort()
          Deprecated.  
 java.lang.String getRandomClass()
          Get the name of the class to be used for generating random numbers by the session id generator.
 RequestInterceptor[] getRequestInterceptors()
          Return the context interceptors as an array.
 RequestInterceptor[] getRequestInterceptors(Request req)
          Return all the interceptors associated with a request.
 int getSecurePort()
           
 java.lang.String getTomcatHome()
          Deprecated.  
 java.lang.String getWorkDir()
          WorkDir property - where all working files will be created
 void handleStatus(Request req, Response res, int code)
          Called for error-codes
 void init()
          Init() is called after the context manager is set up and configured.
 void initContext(Context ctx)
          Initializes this context to be able to accept requests.
 void initRequest(Request req, Response resp)
          Prepare the req/resp pair for use in tomcat.
 void log(java.lang.String msg)
           
 int processRequest(Request req)
          Will find the ServletWrapper for a servlet, assuming we already have the Context.
 void removeContainer(Container container)
          Notify interceptors that a container was removed.
 void removeContext(Context context)
          Shut down and removes a context from service
 void removeContext(java.lang.String name)
          Deprecated. Use removeContext( Context ).
 void service(Request req, Response res)
          This is the entry point in tomcat - the connectors ( or any other component able to generate Request/Response implementations ) will call this method to get it processed.
 void setAccount(int pos, long value)
           
 void setDebug(int level)
           
 void setDefaults()
          Set default settings ( interceptors, connectors, loader, manager ) It is called from init if no connector is set up - note that we try to avoid any "magic" - you either set up everything ( using server.xml or alternatives) or you don't set up and then defaults will be used.
 void setHome(java.lang.String home)
          The home of the tomcat instance - you can have multiple users running tomcat, with a shared install directory.
 void setHostName(java.lang.String host)
          Deprecated.  
 void setInstallDir(java.lang.String tH)
          Set installation directory, where libraries and default files are located.
 void setNote(int pos, java.lang.Object value)
           
 void setPermissions(java.lang.Object permissions)
          Add a Permission to the default Permissions
 void setPort(int port)
          Deprecated.  
 void setRandomClass(java.lang.String randomClass)
          Sets the name of the class used for generating random numbers by the session id generator.
 void setSecurePort(int p)
          Secure port is set to the SSL connector that will handle INTEGRAL/CONFIDENTIAL transport.
 void setTomcatHome(java.lang.String s)
          Deprecated.  
 void setWorkDir(java.lang.String wd)
          WorkDir property - where all working files will be created
 void shutdown()
          Will shutdown all contexts
 void shutdownContext(Context ctx)
          Stop the context and release all resources.
 void start()
          Will start the connectors and begin serving requests.
 void stop()
          Will stop all connectors
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_WORK_DIR

public static final java.lang.String DEFAULT_WORK_DIR
Default work dir, relative to home

MAX_NOTES

public static final int MAX_NOTES
Maximum number of notes supported

RESERVED

public static final int RESERVED

SERVER_NOTE

public static final int SERVER_NOTE

CONTAINER_NOTE

public static final int CONTAINER_NOTE

REQUEST_NOTE

public static final int REQUEST_NOTE

HANDLER_NOTE

public static final int HANDLER_NOTE

REQ_RE_NOTE

public static final int REQ_RE_NOTE

ACC_INIT_START

public static final int ACC_INIT_START

ACC_INIT_END

public static final int ACC_INIT_END

ACCOUNTS

public static final int ACCOUNTS

DEFAULT_HOSTNAME

public static final java.lang.String DEFAULT_HOSTNAME

DEFAULT_PORT

public static final int DEFAULT_PORT
Constructor Detail

ContextManager

public ContextManager()
Construct a new ContextManager instance with default values.
Method Detail

setHome

public void setHome(java.lang.String home)
The home of the tomcat instance - you can have multiple users running tomcat, with a shared install directory. Every instance will have its own logs, webapps directory and local config, all relative to this directory.

getHome

public java.lang.String getHome()
The home of the tomcat instance - you can have multiple users running tomcat, with a shared install directory. Every instance will have its own logs, webapps directory and local config, all relative to this directory. If no home is configured we'll try the install dir XXX clean up the order and process of guessing - maybe we can just throw error instead of guessing wrong.

getInstallDir

public java.lang.String getInstallDir()
Get installation directory, where libraries and default files are located. If path specified is relative, evaluate it relative to the current working directory.

setInstallDir

public void setInstallDir(java.lang.String tH)
Set installation directory, where libraries and default files are located. If path specified is relative, evaluate it relative to the current working directory.

getSecurePort

public int getSecurePort()

setSecurePort

public void setSecurePort(int p)
Secure port is set to the SSL connector that will handle INTEGRAL/CONFIDENTIAL transport. This is an initial solution, it may change !

setWorkDir

public void setWorkDir(java.lang.String wd)
WorkDir property - where all working files will be created

getWorkDir

public java.lang.String getWorkDir()
WorkDir property - where all working files will be created

getPermissions

public java.lang.Object getPermissions()
Get the default Security Permissions for this server

setPermissions

public void setPermissions(java.lang.Object permissions)
Add a Permission to the default Permissions

getRandomClass

public java.lang.String getRandomClass()
Get the name of the class to be used for generating random numbers by the session id generator. By default this is java.security.SecureRandom.

setRandomClass

public void setRandomClass(java.lang.String randomClass)
Sets the name of the class used for generating random numbers by the session id generator.

setDefaults

public void setDefaults()
Set default settings ( interceptors, connectors, loader, manager ) It is called from init if no connector is set up - note that we try to avoid any "magic" - you either set up everything ( using server.xml or alternatives) or you don't set up and then defaults will be used. Set interceptors or call setDefaults before adding contexts. This is mostly used to allow "0 config" case ( you just want the reasonable defaults and nothing else ).

init

public void init()
          throws TomcatException
Init() is called after the context manager is set up and configured. It will init all internal components to be ready for start. There is a difference between Context and Adapters - the adapter has start/stop, the Context has init/shutdown(destroy may be a better name ? ). ( Initializing is different from starting.)

shutdown

public void shutdown()
              throws TomcatException
Will shutdown all contexts

initContext

public void initContext(Context ctx)
                 throws TomcatException
Initializes this context to be able to accept requests. This action will cause the context to load it's configuration information from the webapp directory in the docbase.

This method must be called before any requests are handled by this context. It will be called after the context was added, typically when the engine starts or after the admin added a new context.


shutdownContext

public void shutdownContext(Context ctx)
                     throws TomcatException
Stop the context and release all resources.

start

public void start()
           throws java.lang.Exception
Will start the connectors and begin serving requests. It must be called after init.

stop

public void stop()
          throws java.lang.Exception
Will stop all connectors

getContexts

public java.util.Enumeration getContexts()
Return the list of contexts managed by this server

addContext

public void addContext(Context ctx)
                throws TomcatException
Adds a new Context to the set managed by this ContextManager.
Parameters:
ctx - context to be added.

removeContext

public void removeContext(Context context)
                   throws TomcatException
Shut down and removes a context from service

addContainer

public void addContainer(Container container)
                  throws TomcatException
Notify interceptors that a new container was added.

removeContainer

public void removeContainer(Container container)
                     throws TomcatException
Notify interceptors that a container was removed.

addServerConnector

public void addServerConnector(ServerConnector con)
Add the specified server connector to the those attached to this server.
Parameters:
con - The new server connector

getConnectors

public java.util.Enumeration getConnectors()

addRequestInterceptor

public void addRequestInterceptor(RequestInterceptor ri)

getRequestInterceptors

public RequestInterceptor[] getRequestInterceptors(Request req)
Return all the interceptors associated with a request. That includes global ( context manager ) interceptors, webapp ( Context ) interceptors and possibly interceptors associated with containers ( urls inside the web app ). For performance reasons we use arrays and cache the result inside containers. XXX Todo: container-level interceptors are not supported. Dynamic add of interceptors is not supported.

getRequestInterceptors

public RequestInterceptor[] getRequestInterceptors()
Return the context interceptors as an array. For performance reasons we use an array instead of returning the vector - the interceptors will not change at runtime and array access is faster and easier than vector access

addContextInterceptor

public void addContextInterceptor(ContextInterceptor ci)

getContextInterceptors

public ContextInterceptor[] getContextInterceptors()
Return the context interceptors as an array. For performance reasons we use an array instead of returning the vector - the interceptors will not change at runtime and array access is faster and easier than vector access

initRequest

public void initRequest(Request req,
                        Response resp)
Prepare the req/resp pair for use in tomcat. Call it after you create the request/response objects

service

public void service(Request req,
                    Response res)
This is the entry point in tomcat - the connectors ( or any other component able to generate Request/Response implementations ) will call this method to get it processed. XXX make sure the alghoritm is right, deal with response codes

processRequest

public int processRequest(Request req)
Will find the ServletWrapper for a servlet, assuming we already have the Context. This is also used by Dispatcher and getResource - where the Context is already known.

doAuthenticate

public int doAuthenticate(Request req,
                          Response res)
Call all authentication callbacks. If any of them is able to identify the user it will set the principal in req.

doAuthorize

public int doAuthorize(Request req,
                       Response res,
                       java.lang.String[] roles)
Call all authorization callbacks. The "require valid user" attributes are probably set during the mapping stage ( for efficiency), but it can be done here too.

createRequest

public Request createRequest(Context ctx,
                             java.lang.String urlPath)
Create a new sub-request in a given context, set the context "hint" This is a particular case of sub-request that can't get out of a context ( and we know the context before - so no need to compute it again) Note that session and all stuff will still be computed.

createRequest

public Request createRequest(java.lang.String urlPath)
Create a new sub-request, deal with query string

handleStatus

public void handleStatus(Request req,
                         Response res,
                         int code)
Called for error-codes

getHandlerForPath

public ServletWrapper getHandlerForPath(Context ctx,
                                        java.lang.String path)

getNoteId

public int getNoteId(int noteType,
                     java.lang.String name)
              throws TomcatException
Create a new note id. Interceptors will get an Id at init time for all notes that it needs. Throws exception if too many notes are set ( shouldn't happen in normal use ).
Parameters:
noteType - The note will be associated with the server, container or request.
name - the name of the note.

getNoteName

public java.lang.String getNoteName(int noteType,
                                    int noteId)

setNote

public void setNote(int pos,
                    java.lang.Object value)

getNote

public java.lang.Object getNote(int pos)

addLogger

public void addLogger(org.apache.tomcat.logging.Logger l)

setDebug

public void setDebug(int level)

getDebug

public int getDebug()

log

public final void log(java.lang.String msg)

doLog

public final void doLog(java.lang.String msg)

doLog

public final void doLog(java.lang.String msg,
                        java.lang.Throwable t)

doLog

public final void doLog(java.lang.String msg,
                        java.lang.Throwable t,
                        int level)

setAccount

public void setAccount(int pos,
                       long value)

getAccount

public long getAccount(int pos)

setPort

public void setPort(int port)
Deprecated.  

Sets the port number on which this server listens.
Parameters:
port - The new port number

getPort

public int getPort()
Deprecated.  

Gets the port number on which this server listens.

setHostName

public void setHostName(java.lang.String host)
Deprecated.  

Sets the virtual host name of this server.
Parameters:
host - The new virtual host name

getHostName

public java.lang.String getHostName()
Deprecated.  

Gets the virtual host name of this server.

getContextNames

public java.util.Enumeration getContextNames()
Deprecated. Path is not "unique key".

Get the names of all the contexts in this server.

getContext

public Context getContext(java.lang.String name)
Deprecated. Use an external iterator to find the context that matches your conditions.

Gets a context by it's name, or null if there is no such context.
Parameters:
name - Name of the requested context

removeContext

public void removeContext(java.lang.String name)
                   throws TomcatException
Deprecated. Use removeContext( Context ).

Shut down and removes a context from service.
Parameters:
name - Name of the Context to be removed

doPreServletInit

public void doPreServletInit(Context ctx,
                             ServletWrapper sw)
                      throws TomcatException

doPostServletInit

public void doPostServletInit(Context ctx,
                              ServletWrapper sw)
                       throws TomcatException

doPreServletDestroy

public void doPreServletDestroy(Context ctx,
                                ServletWrapper sw)
                         throws TomcatException

doPostServletDestroy

public void doPostServletDestroy(Context ctx,
                                 ServletWrapper sw)
                          throws TomcatException

setTomcatHome

public void setTomcatHome(java.lang.String s)
Deprecated.  


getTomcatHome

public java.lang.String getTomcatHome()
Deprecated.  


getAbsolute

public java.io.File getAbsolute(java.io.File f)
Convert a relative name to absolute by using the "home" property


Copyright © 2000 Apache Software Foundation. All Rights Reserved.