|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.mortbay.util.Container
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 FormField Summary | |
static java.lang.String |
__ErrorHandler
|
static java.lang.String |
__fileClassPathAttr
File class path attribute. |
Constructor Summary | |
HttpContext()
Constructor. |
|
HttpContext(HttpServer httpServer,
java.lang.String contextPathSpec)
Constructor. |
Method Summary | |
void |
addClassPath(java.lang.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(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. |
java.lang.Object |
enterContextScope(HttpRequest request,
HttpResponse response)
Enter the context scope. |
void |
flushCache()
|
java.lang.Object |
getAttribute(java.lang.String name)
|
java.util.Enumeration |
getAttributeNames()
|
java.util.Map |
getAttributes()
|
Authenticator |
getAuthenticator()
|
Resource |
getBaseResource()
|
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)
|
java.util.Map |
getEncodingMap()
|
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. |
HttpContext |
getHttpContext()
|
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)
|
java.util.Map |
getMimeMap()
|
java.lang.String |
getName()
Get the name of the handler. |
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)
|
java.lang.String |
getResourceBase()
|
ResourceCache.ResourceMetaData |
getResourceMetaData(Resource resource)
|
int |
getResponses1xx()
|
int |
getResponses2xx()
|
int |
getResponses3xx()
|
int |
getResponses4xx()
|
int |
getResponses5xx()
|
java.lang.String[] |
getServerClasses()
Get system classes. |
boolean |
getStatsOn()
|
long |
getStatsOnMs()
|
boolean |
getStopGracefully()
|
java.lang.String[] |
getSystemClasses()
Get system classes. |
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()
|
void |
handle(HttpRequest request,
HttpResponse response)
Handler request. |
void |
handle(java.lang.String pathInContext,
java.lang.String pathParams,
HttpRequest request,
HttpResponse response)
Handler request. |
void |
initialize(HttpContext context)
|
boolean |
isClassLoaderJava2Compliant()
Get Java2 compliant classloading. |
boolean |
isRedirectNullPath()
|
void |
leaveContextScope(HttpRequest request,
HttpResponse response,
java.lang.Object oldScope)
Leave the context scope. |
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)
|
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)
|
static void |
sendContextError(HttpResponse response,
int code,
java.lang.String msg)
Send an error response. |
void |
sendError(HttpResponse response,
int code,
java.lang.String msg)
Send an error response. |
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Set a context attribute. |
void |
setAttributes(java.util.Map attributes)
|
void |
setAuthenticator(Authenticator authenticator)
|
void |
setBaseResource(Resource base)
|
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 |
setContextPath(java.lang.String contextPathSpec)
|
void |
setEncodingMap(java.util.Map encodingMap)
|
void |
setHandlers(HttpHandler[] handlers)
|
void |
setHosts(java.lang.String[] hosts)
Set the hosts for the context. |
void |
setHttpContextName(java.lang.String s)
|
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)
|
void |
setMimeMapping(java.lang.String extension,
java.lang.String type)
|
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)
|
void |
setServerClasses(java.lang.String[] classes)
Set system classes. |
void |
setStatsOn(boolean on)
True set statistics recording on for this context. |
void |
setStopGracefully(boolean graceful)
|
void |
setSystemClasses(java.lang.String[] classes)
Set system classes. |
void |
setTempDirectory(java.io.File dir)
Set temporary directory for context. |
void |
setTypeEncoding(java.lang.String mimeType,
java.lang.String encoding)
|
void |
setVirtualHosts(java.lang.String[] hosts)
Set the virtual hosts for the context. |
void |
setWelcomeFiles(java.lang.String[] welcomes)
|
void |
statsReset()
|
void |
stop(boolean graceful)
Stop the context. |
java.lang.String |
toString()
|
java.lang.String |
toString(boolean detail)
|
Methods inherited from class org.mortbay.util.Container |
addEventListener, getComponents, isStarted, removeEventListener, start, stop |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.mortbay.util.LifeCycle |
isStarted, start, stop |
Methods inherited from interface org.mortbay.util.EventProvider |
addEventListener, removeEventListener |
Field Detail |
public static final java.lang.String __fileClassPathAttr
public static final java.lang.String __ErrorHandler
Constructor Detail |
public HttpContext()
public HttpContext(HttpServer httpServer, java.lang.String contextPathSpec)
httpServer
- contextPathSpec
- Method Detail |
public HttpConnection getHttpConnection()
public HttpServer getHttpServer()
public void setStopGracefully(boolean graceful)
public boolean getStopGracefully()
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 java.lang.String[] getVirtualHosts()
public void setHosts(java.lang.String[] hosts) throws java.net.UnknownHostException
java.net.UnknownHostException
public java.lang.String[] getHosts()
public void setSystemClasses(java.lang.String[] classes)
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.public java.lang.String[] getSystemClasses()
public void setServerClasses(java.lang.String[] classes)
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.public java.lang.String[] getServerClasses()
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 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 java.lang.String getWelcomeFile(Resource resource) throws java.io.IOException
java.io.IOException
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 addClassPath(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 addClassPaths(Resource lib)
lib
- the resource that contains the jar and/or zip files.setClassPath(String)
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 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 Authenticator getAuthenticator()
public void setAuthenticator(Authenticator authenticator)
public void addSecurityConstraint(java.lang.String pathSpec, SecurityConstraint sc)
public void clearSecurityConstraints()
public boolean checkSecurityConstraints(java.lang.String pathInContext, HttpRequest request, HttpResponse response) throws HttpException, java.io.IOException
HttpException
java.io.IOException
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 void handle(HttpRequest request, HttpResponse response) throws HttpException, java.io.IOException
request
- response
-
HttpException
java.io.IOException
public void handle(java.lang.String pathInContext, java.lang.String pathParams, HttpRequest request, HttpResponse response) throws HttpException, java.io.IOException
handle
in interface HttpHandler
pathInContext
- Path in contextpathParams
- Path parameters such as encoded Session IDrequest
- response
-
HttpException
java.io.IOException
public java.lang.Object enterContextScope(HttpRequest request, HttpResponse response)
public void leaveContextScope(HttpRequest request, HttpResponse response, java.lang.Object oldScope)
public java.lang.String getHttpContextName()
public void setHttpContextName(java.lang.String s)
public java.lang.String toString()
public java.lang.String toString(boolean detail)
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 destroy()
destroy
in class Container
public void setRequestLog(RequestLog log)
log
- RequestLog to use.public RequestLog getRequestLog()
public void sendError(HttpResponse response, int code, java.lang.String msg) throws java.io.IOException
response
- the response to sendcode
- The error codemsg
- The message for the error or null for the default
java.io.IOException
- Problem sending response.public static void sendContextError(HttpResponse response, int code, java.lang.String msg) throws java.io.IOException
response
- the response to sendcode
- The error codemsg
- The message for the error or null for the default
java.io.IOException
- Problem sending response.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 java.lang.String getName()
HttpHandler
getName
in interface HttpHandler
public HttpContext getHttpContext()
getHttpContext
in interface HttpHandler
public void initialize(HttpContext context)
initialize
in interface HttpHandler
public Resource getBaseResource()
public java.lang.String getEncodingByMimeType(java.lang.String type)
type
-
public java.util.Map getEncodingMap()
public int getMaxCachedFileSize()
public int getMaxCacheSize()
public java.lang.String getMimeByExtension(java.lang.String filename)
filename
-
public java.util.Map getMimeMap()
public Resource getResource(java.lang.String pathInContext) throws java.io.IOException
pathInContext
-
java.io.IOException
public java.lang.String getResourceBase()
public ResourceCache.ResourceMetaData getResourceMetaData(Resource resource)
resource
-
public void setBaseResource(Resource base)
base
- public void setEncodingMap(java.util.Map encodingMap)
encodingMap
- public void setMaxCachedFileSize(int maxCachedFileSize)
maxCachedFileSize
- public void setMaxCacheSize(int maxCacheSize)
maxCacheSize
- public void setMimeMap(java.util.Map mimeMap)
mimeMap
- public void setMimeMapping(java.lang.String extension, java.lang.String type)
extension
- type
- public void setResourceBase(java.lang.String resourceBase)
resourceBase
- public void setTypeEncoding(java.lang.String mimeType, java.lang.String encoding)
mimeType
- encoding
-
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |