|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.mortbay.http.HttpContext
Context for a collection of HttpHandlers. HTTP Context provides an ordered container for HttpHandlers that share the same path prefix, filebase, resourcebase and/or classpath.
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.
HttpServer
,
HttpHandler
,
ServletHttpContext
,
Serialized FormNested Class Summary | |
class |
HttpContext.ResourceMetaData
MetaData associated with a context Resource. |
Field Summary | |
static java.lang.String |
__fileClassPathAttr
File class path attribute. |
Constructor Summary | |
HttpContext()
Constructor. |
|
HttpContext(HttpServer httpServer,
java.lang.String contextPathSpec)
Constructor. |
Method Summary | |
void |
addHandler(HttpHandler handler)
Add a HttpHandler to the context. |
void |
addHandler(int i,
HttpHandler handler)
Add a handler. |
void |
addPermission(java.security.Permission permission)
Add a permission to this context. |
void |
addSecurityConstraint(java.lang.String pathSpec,
SecurityConstraint sc)
|
void |
addVirtualHost(java.lang.String hostname)
Add a virtual host alias to this context. |
void |
addWelcomeFile(java.lang.String welcomeFile)
|
static java.lang.String |
canonicalContextPathSpec(java.lang.String contextPathSpec)
|
boolean |
checkSecurityConstraints(java.lang.String pathInContext,
HttpRequest request,
HttpResponse response)
|
void |
clearSecurityConstraints()
|
void |
destroy()
Destroy a context. |
void |
flushCache()
|
java.lang.Object |
getAttribute(java.lang.String name)
|
java.util.Enumeration |
getAttributeNames()
|
java.util.Map |
getAttributes()
|
SecurityConstraint.Authenticator |
getAuthenticator()
|
Resource |
getBaseResource()
Get the base resource. |
java.lang.ClassLoader |
getClassLoader()
Get the classloader. |
java.lang.String |
getClassPath()
Get the context classpath. |
java.lang.String |
getContextPath()
|
java.lang.String |
getEncodingByMimeType(java.lang.String type)
Get char encoding by mime type. |
java.util.Map |
getEncodingMap()
Get the map of mime type to char encoding. |
java.lang.String |
getErrorPage(java.lang.String error)
get error page URI. |
java.lang.String |
getFileClassPath()
Get the file classpath of the context. |
HttpHandler |
getHandler(java.lang.Class handlerClass)
Get a handler by class. |
int |
getHandlerIndex(HttpHandler handler)
Get handler index. |
HttpHandler[] |
getHandlers()
Get all handlers. |
java.lang.String[] |
getHosts()
Get the hosts for the context. |
HttpConnection |
getHttpConnection()
Get the ThreadLocal HttpConnection. |
java.lang.String |
getHttpContextName()
|
HttpServer |
getHttpServer()
|
java.lang.String |
getInitParameter(java.lang.String param)
Get context init parameter. |
java.util.Enumeration |
getInitParameterNames()
Get context init parameter. |
int |
getMaxCachedFileSize()
|
int |
getMaxCacheSize()
|
java.lang.String |
getMimeByExtension(java.lang.String filename)
Get the MIME type by filename extension. |
java.util.Map |
getMimeMap()
|
java.lang.ClassLoader |
getParentClassLoader()
|
java.security.PermissionCollection |
getPermissions()
Get the permissions to be used for this context. |
UserRealm |
getRealm()
|
java.lang.String |
getRealmName()
|
RequestLog |
getRequestLog()
|
int |
getRequests()
|
int |
getRequestsActive()
|
int |
getRequestsActiveMax()
|
Resource |
getResource(java.lang.String pathInContext)
Get a resource from the context. |
java.lang.String |
getResourceBase()
Set the Resource Base. |
HttpContext.ResourceMetaData |
getResourceMetaData(Resource resource)
Get Resource MetaData. |
int |
getResponses1xx()
|
int |
getResponses2xx()
|
int |
getResponses3xx()
|
int |
getResponses4xx()
|
int |
getResponses5xx()
|
boolean |
getStatsOn()
|
long |
getStatsOnMs()
|
java.io.File |
getTempDirectory()
Get Context temporary directory. |
java.lang.String[] |
getVirtualHosts()
Get the virtual hosts for the context. |
java.lang.String |
getWelcomeFile(Resource resource)
|
java.lang.String[] |
getWelcomeFiles()
|
boolean |
handle(HttpRequest request,
HttpResponse response)
Handler request. |
boolean |
handle(java.lang.String pathInContext,
java.lang.String pathParams,
HttpRequest request,
HttpResponse response)
Handler request. |
boolean |
isAuthConstrained()
|
boolean |
isClassLoaderJava2Compliant()
Get Java2 compliant classloading. |
boolean |
isRedirectNullPath()
|
boolean |
isStarted()
|
java.lang.Class |
loadClass(java.lang.String className)
|
void |
log(HttpRequest request,
HttpResponse response,
int length)
Log a request and response. |
void |
removeAttribute(java.lang.String name)
|
java.lang.String |
removeErrorPage(java.lang.String error)
|
void |
removeHandler(HttpHandler handler)
Remove a handler. |
HttpHandler |
removeHandler(int i)
Remove a handler. |
void |
removeVirtualHost(java.lang.String hostname)
remove a virtual host alias to this context. |
void |
removeWelcomeFile(java.lang.String welcomeFile)
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Set a context attribute. |
void |
setAttributes(java.util.Map attributes)
|
void |
setAuthenticator(SecurityConstraint.Authenticator authenticator)
|
void |
setBaseResource(Resource base)
Set the base resource. |
void |
setClassLoader(java.lang.ClassLoader loader)
Set ClassLoader. |
void |
setClassLoaderJava2Compliant(boolean compliant)
Set Java2 compliant classloading. |
void |
setClassPath(java.lang.String classPath)
Sets the class path for the context. |
void |
setClassPaths(Resource lib,
boolean append)
Sets the class path for the context from the jar and zip files found in the specified resource. |
void |
setClassPaths(java.lang.String lib,
boolean append)
Sets the class path for the context from the jar and zip files found in the specified resource. |
void |
setContextPath(java.lang.String contextPathSpec)
|
void |
setEncodingMap(java.util.Map encodingMap)
Set the map of mime type to char encoding. |
void |
setErrorPage(java.lang.String error,
java.lang.String uriInContext)
set error page URI. |
void |
setHandlers(HttpHandler[] handlers)
|
void |
setHosts(java.lang.String[] hosts)
Set the hosts for the context. |
void |
setInitParameter(java.lang.String param,
java.lang.String value)
Set context init parameter. |
void |
setMaxCachedFileSize(int maxCachedFileSize)
|
void |
setMaxCacheSize(int maxCacheSize)
|
void |
setMimeMap(java.util.Map mimeMap)
Also sets the org.mortbay.http.mimeMap context attribute |
void |
setMimeMapping(java.lang.String extension,
java.lang.String type)
Set a mime mapping |
void |
setParentClassLoader(java.lang.ClassLoader loader)
Set Parent ClassLoader. |
void |
setPermissions(java.security.PermissionCollection permissions)
Set the permissions to be used for this context. |
void |
setRealm(UserRealm realm)
Set the realm. |
void |
setRealmName(java.lang.String realmName)
Set the realm name. |
void |
setRedirectNullPath(boolean b)
Set null path redirection. |
void |
setRequestLog(RequestLog log)
Set the request log. |
void |
setResourceBase(java.lang.String resourceBase)
Set the Resource Base. |
void |
setStatsOn(boolean on)
True set statistics recording on for this context. |
void |
setTempDirectory(java.io.File dir)
Set temporary directory for context. |
void |
setTypeEncoding(java.lang.String mimeType,
java.lang.String encoding)
Set the encoding that should be used for a mimeType. |
void |
setVirtualHosts(java.lang.String[] hosts)
Set the virtual hosts for the context. |
void |
setWelcomeFiles(java.lang.String[] welcomes)
|
void |
start()
Start the LifeCycle. |
void |
statsReset()
|
void |
stop()
Stop the context. |
void |
stop(boolean graceful)
Stop the context. |
java.lang.String |
toString()
|
java.lang.String |
toString(boolean detail)
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final java.lang.String __fileClassPathAttr
Constructor Detail |
public HttpContext()
public HttpContext(HttpServer httpServer, java.lang.String contextPathSpec)
httpServer
- contextPathSpec
- Method Detail |
public HttpConnection getHttpConnection()
public HttpServer getHttpServer()
public static java.lang.String canonicalContextPathSpec(java.lang.String contextPathSpec)
public void setContextPath(java.lang.String contextPathSpec)
public java.lang.String getContextPath()
public void addVirtualHost(java.lang.String hostname)
hostname
- A hostname. A null host name means any hostname is
acceptable. Host names may String representation of IP addresses.setVirtualHosts(java.lang.String[])
public void removeVirtualHost(java.lang.String hostname)
hostname
- A hostname. A null host name means any hostname is
acceptable. Host names may String representation of IP addresses.setVirtualHosts(java.lang.String[])
public void setVirtualHosts(java.lang.String[] hosts)
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.public void setHosts(java.lang.String[] hosts) throws java.net.UnknownHostException
java.net.UnknownHostException
public java.lang.String[] getHosts()
public java.lang.String[] getVirtualHosts()
public void setHandlers(HttpHandler[] handlers)
public HttpHandler[] getHandlers()
public void addHandler(int i, HttpHandler handler)
i
- The position in the handler listhandler
- The handler.public void addHandler(HttpHandler handler)
handler
- public int getHandlerIndex(HttpHandler handler)
handler
- instance
public HttpHandler getHandler(java.lang.Class handlerClass)
handlerClass
-
public HttpHandler removeHandler(int i)
i
- index of handlerpublic void removeHandler(HttpHandler handler)
public void setInitParameter(java.lang.String param, java.lang.String value)
param
- param namevalue
- param value or nullpublic java.lang.String getInitParameter(java.lang.String param)
param
- param name
public java.util.Enumeration getInitParameterNames()
public void setAttribute(java.lang.String name, java.lang.Object value)
name
- attribute namevalue
- attribute valuepublic java.lang.Object getAttribute(java.lang.String name)
name
- attribute name
public java.util.Map getAttributes()
public void setAttributes(java.util.Map attributes)
public java.util.Enumeration getAttributeNames()
public void removeAttribute(java.lang.String name)
name
- attribute namepublic java.lang.String getResourceBase()
public void setResourceBase(java.lang.String resourceBase)
resourceBase
- A URL prefix or directory name.public Resource getBaseResource()
public void setBaseResource(Resource base)
base
- The resourceBase as a Resource instancepublic int getMaxCachedFileSize()
public void setMaxCachedFileSize(int maxCachedFileSize)
public int getMaxCacheSize()
public void setMaxCacheSize(int maxCacheSize)
public void flushCache()
public java.lang.String[] getWelcomeFiles()
public void setWelcomeFiles(java.lang.String[] welcomes)
public void addWelcomeFile(java.lang.String welcomeFile)
public void removeWelcomeFile(java.lang.String welcomeFile)
public Resource getResource(java.lang.String pathInContext) throws java.io.IOException
pathInContext
-
java.io.IOException
public java.lang.String getWelcomeFile(Resource resource) throws java.io.IOException
java.io.IOException
public java.util.Map getMimeMap()
public void setMimeMap(java.util.Map mimeMap)
mimeMap
- public java.lang.String getMimeByExtension(java.lang.String filename)
filename
- A file name
public void setMimeMapping(java.lang.String extension, java.lang.String type)
extension
- type
- public java.lang.String getClassPath()
getFileClassPath()
public java.lang.String getFileClassPath() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- HttpContext.initClassLoader
has not been called.public void setClassPath(java.lang.String classPath)
classPath
- a comma or ';' separated list of class
resources. These may be jar files, directories or URLs to jars
or directories.public void setClassPaths(Resource lib, boolean append)
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.setClassPath(String)
public void setClassPaths(java.lang.String lib, boolean append) throws java.io.IOException
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 are to be prepended.
java.io.IOException
public boolean isClassLoaderJava2Compliant()
public void setClassLoaderJava2Compliant(boolean compliant)
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.public void setTempDirectory(java.io.File dir)
dir
- Writable temporary directory.public java.io.File getTempDirectory()
public void setClassLoader(java.lang.ClassLoader loader)
loader
- The loader to be used by this context.public java.lang.ClassLoader getClassLoader()
public void setParentClassLoader(java.lang.ClassLoader loader)
loader
- The class loader to use for the parent loader of
the context classloader.public java.lang.ClassLoader getParentClassLoader()
public java.lang.Class loadClass(java.lang.String className) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public void setErrorPage(java.lang.String error, java.lang.String uriInContext)
error
- A string representing an error code or a
exception classnameuriInContext
- public java.lang.String getErrorPage(java.lang.String error)
error
- A string representing an error code or a
exception classname
public java.lang.String removeErrorPage(java.lang.String error)
public void setRealmName(java.lang.String realmName)
realmName
- The name to use to retrieve the actual realm
from the HttpServerpublic java.lang.String getRealmName()
public void setRealm(UserRealm realm)
public UserRealm getRealm()
public SecurityConstraint.Authenticator getAuthenticator()
public void setAuthenticator(SecurityConstraint.Authenticator authenticator)
public void addSecurityConstraint(java.lang.String pathSpec, SecurityConstraint sc)
public boolean isAuthConstrained()
public void clearSecurityConstraints()
public boolean checkSecurityConstraints(java.lang.String pathInContext, HttpRequest request, HttpResponse response) throws HttpException, java.io.IOException
HttpException
java.io.IOException
public java.util.Map getEncodingMap()
public void setEncodingMap(java.util.Map encodingMap)
encodingMap
- Map of mime type to character encodings.public java.lang.String getEncodingByMimeType(java.lang.String type)
type
- A mime type.
public void setTypeEncoding(java.lang.String mimeType, java.lang.String encoding)
mimeType
- encoding
- public void setRedirectNullPath(boolean b)
b
- if true a /context request will be redirected to
/context/ if there is not path in the context.public boolean isRedirectNullPath()
public void setPermissions(java.security.PermissionCollection permissions)
permissions
- public java.security.PermissionCollection getPermissions()
public void addPermission(java.security.Permission permission)
permission
- public boolean handle(HttpRequest request, HttpResponse response) throws HttpException, java.io.IOException
request
- response
-
HttpException
java.io.IOException
public boolean handle(java.lang.String pathInContext, java.lang.String pathParams, HttpRequest request, HttpResponse response) throws HttpException, java.io.IOException
pathInContext
- Path in contextpathParams
- Path parameters such as encoded Session IDrequest
- response
-
HttpException
java.io.IOException
public java.lang.String getHttpContextName()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean detail)
public void start() throws java.lang.Exception
LifeCycle
start
in interface LifeCycle
java.lang.Exception
- An arbitrary exception may be thrown.public boolean isStarted()
isStarted
in interface LifeCycle
public void stop(boolean graceful) throws java.lang.InterruptedException
graceful
- If true and statistics are on, then this method will wait
for requestsActive to go to zero before calling stop()
java.lang.InterruptedException
public void stop() throws java.lang.InterruptedException
stop
in interface LifeCycle
java.lang.InterruptedException
- Stopping a lifecycle is rarely atomic
and may be interrupted by another thread. If this happens
InterruptedException is throw and the component will be in an
indeterminant state and should probably be discarded.public void destroy()
public void setRequestLog(RequestLog log)
log
- RequestLog to use.public RequestLog getRequestLog()
public void setStatsOn(boolean on)
on
- If true, statistics will be recorded for this context.public boolean getStatsOn()
public long getStatsOnMs()
public void statsReset()
public int getRequests()
public int getRequestsActive()
public int getRequestsActiveMax()
public int getResponses1xx()
public int getResponses2xx()
public int getResponses3xx()
public int getResponses4xx()
public int getResponses5xx()
public void log(HttpRequest request, HttpResponse response, int length)
request
- response
- public HttpContext.ResourceMetaData getResourceMetaData(Resource resource)
resource
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |