org.mortbay.http
public class HttpContext extends Container implements LifeCycle, HttpHandler, EventProvider, Serializable
A HttpContext is analagous to a ServletContext in the Servlet API, except that it may contain other types of handler other than servlets.
A ClassLoader is created for the context and it uses Thread.currentThread().getContextClassLoader(); as it's parent loader. The class loader is initialized during start(), when a derived context calls initClassLoader() or on the first call to loadClass()
Note. that order is important when configuring a HttpContext. For example, if resource serving is enabled before servlets, then resources take priority.
Version: $Id: HttpContext.java,v 1.136 2006/02/21 09:47:43 gregwilkins Exp $
See Also: HttpServer HttpHandler ServletHttpContext
Field Summary | |
---|---|
static String | __ErrorHandler |
static String | __fileClassPathAttr File class path attribute.
|
Constructor Summary | |
---|---|
HttpContext() Constructor. | |
HttpContext(HttpServer httpServer, String contextPathSpec) Constructor. |
Method Summary | |
---|---|
void | addClassPath(String classPath) Add the class path element to the context.
|
void | addClassPaths(Resource lib) Add elements to the class path for the context from the jar and zip files found
in the specified resource. |
void | addHandler(int i, HttpHandler handler) Add a handler. |
void | addHandler(HttpHandler handler) Add a HttpHandler to the context. |
void | addPermission(Permission permission) Add a permission to this context.
|
void | addSecurityConstraint(String pathSpec, SecurityConstraint sc) |
void | addVirtualHost(String hostname) Add a virtual host alias to this context. |
void | addWelcomeFile(String welcomeFile) |
static String | canonicalContextPathSpec(String contextPathSpec) |
boolean | checkSecurityConstraints(String pathInContext, HttpRequest request, HttpResponse response) |
void | clearSecurityConstraints() |
void | destroy() Destroy a context.
|
protected void | doStart() |
protected void | doStop() Stop the context. |
Object | enterContextScope(HttpRequest request, HttpResponse response) Enter the context scope.
|
void | flushCache() |
Object | getAttribute(String name) |
Enumeration | getAttributeNames() |
Map | getAttributes() |
Authenticator | getAuthenticator() |
Resource | getBaseResource() |
ClassLoader | getClassLoader() Get the classloader.
|
String | getClassPath() Get the context classpath.
|
String | getContextPath() |
String | getEncodingByMimeType(String type) |
Map | getEncodingMap() |
String | getFileClassPath() Get the file classpath of the context.
|
HttpHandler | getHandler(Class handlerClass) Get a handler by class. |
int | getHandlerIndex(HttpHandler handler) Get handler index. |
HttpHandler[] | getHandlers() Get all handlers. |
String[] | getHosts() Get the hosts for the context. |
HttpConnection | getHttpConnection() Get the ThreadLocal HttpConnection.
|
HttpContext | getHttpContext() |
String | getHttpContextName() |
HttpServer | getHttpServer() |
String | getInitParameter(String param) Get context init parameter. |
Enumeration | getInitParameterNames() Get context init parameter. |
int | getMaxCachedFileSize() |
int | getMaxCacheSize() |
String | getMimeByExtension(String filename) |
Map | getMimeMap() |
String | getName() |
ClassLoader | getParentClassLoader() |
PermissionCollection | getPermissions() Get the permissions to be used for this context. |
UserRealm | getRealm() |
String | getRealmName() |
RequestLog | getRequestLog() |
int | getRequests() |
int | getRequestsActive() |
int | getRequestsActiveMax() |
Resource | getResource(String pathInContext) |
String | getResourceBase() |
ResourceCache.ResourceMetaData | getResourceMetaData(Resource resource) |
int | getResponses1xx() |
int | getResponses2xx() |
int | getResponses3xx() |
int | getResponses4xx() |
int | getResponses5xx() |
String[] | getServerClasses() Get system classes.
|
boolean | getStatsOn() |
long | getStatsOnMs() |
boolean | getStopGracefully() |
String[] | getSystemClasses() Get system classes.
|
File | getTempDirectory() Get Context temporary directory.
|
String[] | getVirtualHosts() Get the virtual hosts for the context.
|
String | getWelcomeFile(Resource resource) |
String[] | getWelcomeFiles() |
void | handle(HttpRequest request, HttpResponse response) Handler request.
|
void | handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) Handler request.
|
protected void | initClassLoader(boolean forceContextLoader) Initialize the context classloader.
|
void | initialize(HttpContext context) |
boolean | isClassLoaderJava2Compliant() Get Java2 compliant classloading. |
boolean | isRedirectNullPath() |
void | leaveContextScope(HttpRequest request, HttpResponse response, Object oldScope) Leave the context scope.
|
Class | loadClass(String className) |
void | log(HttpRequest request, HttpResponse response, int length) Log a request and response.
|
void | removeAttribute(String name) |
HttpHandler | removeHandler(int i) Remove a handler.
|
void | removeHandler(HttpHandler handler) Remove a handler.
|
void | removeVirtualHost(String hostname) remove a virtual host alias to this context. |
void | removeWelcomeFile(String welcomeFile) |
static void | sendContextError(HttpResponse response, int code, String msg) Send an error response.
|
void | sendError(HttpResponse response, int code, String msg) Send an error response.
|
void | setAttribute(String name, Object value) Set a context attribute. |
void | setAttributes(Map attributes) |
void | setAuthenticator(Authenticator authenticator) |
void | setBaseResource(Resource base) |
void | setClassLoader(ClassLoader loader) Set ClassLoader. |
void | setClassLoaderJava2Compliant(boolean compliant) Set Java2 compliant classloading. |
void | setClassPath(String classPath) Sets the class path for the context.
|
void | setContextPath(String contextPathSpec) |
void | setEncodingMap(Map encodingMap) |
void | setHandlers(HttpHandler[] handlers) |
void | setHosts(String[] hosts) Set the hosts for the context.
|
void | setHttpContextName(String s) |
void | setInitParameter(String param, String value) Set context init parameter.
|
void | setMaxCachedFileSize(int maxCachedFileSize) |
void | setMaxCacheSize(int maxCacheSize) |
void | setMimeMap(Map mimeMap) |
void | setMimeMapping(String extension, String type) |
void | setParentClassLoader(ClassLoader loader) Set Parent ClassLoader.
|
void | setPermissions(PermissionCollection permissions) Set the permissions to be used for this context.
|
void | setRealm(UserRealm realm) Set the realm. |
void | setRealmName(String realmName) Set the realm name. |
void | setRedirectNullPath(boolean b) Set null path redirection. |
void | setRequestLog(RequestLog log) Set the request log. |
void | setResourceBase(String resourceBase) |
void | setServerClasses(String[] classes) Set system classes.
|
void | setStatsOn(boolean on) True set statistics recording on for this context. |
void | setStopGracefully(boolean graceful) |
void | setSystemClasses(String[] classes) Set system classes.
|
void | setTempDirectory(File dir) Set temporary directory for context.
|
void | setTypeEncoding(String mimeType, String encoding) |
void | setVirtualHosts(String[] hosts) Set the virtual hosts for the context.
|
void | setWelcomeFiles(String[] welcomes) |
protected void | startHandlers() Start the handlers.
|
void | statsReset() |
void | stop(boolean graceful) Stop the context. |
String | toString() |
String | toString(boolean detail) |
Parameters: httpServer contextPathSpec
Parameters: classPath a comma or ';' separated list of class resources. These may be jar files, directories or URLs to jars or directories.
Parameters: lib the resource that contains the jar and/or zip files. append true if the classpath entries are to be appended to any existing classpath, or false if they replace the existing classpath.
See Also: setClassPath
Parameters: i The position in the handler list handler The handler.
Parameters: handler
Parameters: permission
Parameters: hostname A hostname. A null host name means any hostname is acceptable. Host names may String representation of IP addresses.
See Also: HttpContext
Parameters: name attribute name
Returns: attribute value or null
Returns: enumaration of names.
Returns:
Returns: Classloader or null.
Returns: a comma or ';' separated list of class resources. These may be jar files, directories or URLs to jars or directories.
See Also: getFileClassPath
Returns: The context prefix
Parameters: type
Returns:
Returns:
Returns: Path of files and directories for loading classes.
Throws: IllegalStateException HttpContext.initClassLoader has not been called.
Parameters: handlerClass
Returns: The first handler that is an instance of the handlerClass
Parameters: handler instance
Returns: Index of handler in context or -1 if not found.
Returns: List of all HttpHandlers
Returns: HttpConnection for this thread.
Parameters: param param name
Returns: param value or null
Returns: Enumeration of names
Returns:
Returns:
Parameters: filename
Returns:
Returns:
Returns: Get the number of requests handled by this context since last call of statsReset(). If setStatsOn(false) then this is undefined.
Returns: Number of requests currently active. Undefined if setStatsOn(false).
Returns: Maximum number of active requests since statsReset() called. Undefined if setStatsOn(false).
Parameters: pathInContext
Returns:
Throws: IOException
Returns:
Parameters: resource
Returns:
Returns: Get the number of responses with a 2xx status returned by this context since last call of statsReset(). Undefined if if setStatsOn(false).
Returns: Get the number of responses with a 100 status returned by this context since last call of statsReset(). Undefined if if setStatsOn(false).
Returns: Get the number of responses with a 3xx status returned by this context since last call of statsReset(). Undefined if if setStatsOn(false).
Returns: Get the number of responses with a 4xx status returned by this context since last call of statsReset(). Undefined if if setStatsOn(false).
Returns: Get the number of responses with a 5xx status returned by this context since last call of statsReset(). Undefined if if setStatsOn(false).
Returns: array of classname Strings. Names ending with '.' are treated as package names. Names starting with '-' are treated as negative matches and must be listed before any enclosing packages. Null if not set.
Returns: array of classname Strings. Names ending with '.' are treated as package names. Names starting with '-' are treated as negative matches and must be listed before any enclosing packages. Null if not set.
Returns: Temporary directory as a File.
Returns: Array of virtual hosts that this context responds to. A null host name or empty array means any hostname is acceptable. Host names may be String representation of IP addresses.
Parameters: request response
Returns: True if the request has been handled.
Throws: HttpException IOException
Parameters: pathInContext Path in context pathParams Path parameters such as encoded Session ID request response
Returns: True if the request has been handled.
Throws: HttpException IOException
Parameters: forceContextLoader If true, a ContextLoader is always if no loader has been set.
Returns: If true, the class loader will conform to the java 2 specification and delegate all loads to the parent classloader. If false, the context classloader only delegate loads for system classes or classes that it can't find itself.
Returns: True if a /context request is redirected to /context/ if there is not path in the context.
Parameters: request response
Parameters: name attribute name
Parameters: i index of handler
Parameters: hostname A hostname. A null host name means any hostname is acceptable. Host names may String representation of IP addresses.
See Also: HttpContext
Parameters: response the response to send code The error code msg The message for the error or null for the default
Throws: IOException Problem sending response.
Parameters: response the response to send code The error code msg The message for the error or null for the default
Throws: IOException Problem sending response.
Parameters: name attribute name value attribute value
Parameters: base
Parameters: loader The loader to be used by this context.
Parameters: compliant If true, the class loader will conform to the java 2 specification and delegate all loads to the parent classloader. If false, the context classloader only delegate loads for system classes or classes that it can't find itself.
Parameters: classPath a comma or ';' separated list of class resources. These may be jar files, directories or URLs to jars or directories.
Parameters: encodingMap
Parameters: param param name value param value or null
Parameters: maxCachedFileSize
Parameters: maxCacheSize
Parameters: mimeMap
Parameters: extension type
Parameters: loader The class loader to use for the parent loader of the context classloader.
Parameters: permissions
Parameters: realmName The name to use to retrieve the actual realm from the HttpServer
Parameters: b if true a /context request will be redirected to /context/ if there is not path in the context.
Parameters: log RequestLog to use.
Parameters: resourceBase
Parameters: classes array of classname Strings. Names ending with '.' are treated as package names. Names starting with '-' are treated as negative matches and must be listed before any enclosing packages.
Parameters: on If true, statistics will be recorded for this context.
Parameters: classes array of classname Strings. Names ending with '.' are treated as package names. Names starting with '-' are treated as negative matches and must be listed before any enclosing packages.
Parameters: dir Writable temporary directory.
Parameters: mimeType encoding
Parameters: hosts Array of virtual hosts that this context responds to. A null host name or null/empty array means any hostname is acceptable. Host names may String representation of IP addresses.
Throws: Exception
Parameters: graceful If true and statistics are on, then this method will wait for requestsActive to go to zero before calling stop()