|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.mortbay.http.HandlerContext
Context for a collection of HttpHandlers. Handler Context provides an ordered container for HttpHandlers that share the same path prefix, filebase, resourcebase and/or classpath.
A HandlerContext is analageous to a ServletContext in the Servlet API, except that it may contain other types of handler other than servlets.
Convenience methods are provided for adding common handlers. See org.mortbay.jetty.JettyContext for conveniance methods for servlets. Note. that order is important when configuring a HandlerContext. For example, if resource serving is enabled before servlets, then resources take priority.
HttpServer
,
HttpHandler
Method Summary | |
void |
addAuthConstraint(java.lang.String pathSpec,
java.lang.String role)
Add an auth security constraint. |
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)
Add a security constraint. |
void |
destroy()
Stop all listeners then handlers. |
java.lang.Object |
getAttribute(java.lang.String name)
|
java.util.Enumeration |
getAttributeNames()
|
Resource |
getBaseResource()
Get the base resource. |
java.lang.ClassLoader |
getClassLoader()
Get the classloader. |
java.lang.String |
getClassPath()
|
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. |
HttpHandler |
getHandler(java.lang.Class handlerClass)
Get a handler by class. |
HttpHandler |
getHandler(int i)
Get handler by index. |
int |
getHandlerIndex(HttpHandler handler)
Get handler index. |
java.util.List |
getHandlers()
Get all handlers. |
int |
getHandlerSize()
Gent the number of handlers. |
java.util.List |
getHosts()
|
HttpServer |
getHttpServer()
|
boolean |
getHttpServerAccess()
Get HttpServer Access. |
java.lang.String |
getInitParameter(java.lang.String param)
Get context init parameter. |
java.util.Enumeration |
getInitParameterNames()
Get context init parameter. |
LogSink |
getLogSink()
Deprecated. use HttpServer.getRequestLogSink() |
java.lang.String |
getMimeByExtension(java.lang.String filename)
|
java.util.Map |
getMimeMap()
|
java.security.PermissionCollection |
getPermissions()
Get the permissions to be used for this context. |
java.lang.String |
getRealm()
|
int |
getRequests()
|
Resource |
getResource(java.lang.String path)
Get a Resource from the context. |
java.lang.String |
getResourceAlias(java.lang.String alias)
|
java.lang.String |
getResourceBase()
Set the Resource Base. |
ResourceHandler |
getResourceHandler()
Get the context ResourceHandler. |
int |
getResponses1xx()
|
int |
getResponses2xx()
|
int |
getResponses3xx()
|
int |
getResponses4xx()
|
int |
getResponses5xx()
|
SecurityHandler |
getSecurityHandler()
Get the context SecurityHandler. |
boolean |
getStatsOn()
|
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 |
isDestroyed()
|
boolean |
isRedirectNullPath()
|
boolean |
isServingResources()
|
boolean |
isStarted()
Start all handlers then listeners. |
void |
registerHost(java.lang.String hostname)
Register a host mapping for this context. |
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. |
java.lang.String |
removeResourceAlias(java.lang.String alias)
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
|
void |
setBaseResource(Resource base)
Set the base resource. |
void |
setClassLoader(java.lang.ClassLoader loader)
Set the class loader. |
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 |
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 |
setHttpServerAccess(boolean access)
Set HttpServer Access. |
void |
setInitParameter(java.lang.String param,
java.lang.String value)
Set context init parameter. |
void |
setLogSink(LogSink logSink)
Deprecated. use HttpServersetRequestLogSink() |
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 |
setPermissions(java.security.PermissionCollection permissions)
Set the permissions to be used for this context. |
void |
setRealm(java.lang.String realmName)
Set the SecurityHandler realm name. |
void |
setRealm(java.lang.String realmName,
UserRealm realm)
Set the SecurityHandler realm. |
void |
setRedirectNullPath(boolean b)
Set null path redirection. |
void |
setResourceAlias(java.lang.String alias,
java.lang.String uri)
Set Resource Alias. |
void |
setResourceBase(java.lang.String resourceBase)
Set the Resource Base. |
void |
setServingResources(boolean serve)
Setup context for serving Resources as files. |
void |
setStatsOn(boolean on)
True set statistics recording on for this context. |
void |
setTypeEncoding(java.lang.String mimeType,
java.lang.String encoding)
Set the encoding that should be used for a mimeType. |
void |
start()
Start all handlers then listeners. |
void |
statsReset()
|
void |
stop()
Stop all listeners then handlers. |
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 |
Method Detail |
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 namepublic 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 namepublic java.util.Enumeration getAttributeNames()
public void removeAttribute(java.lang.String name)
name
- attribute namepublic void registerHost(java.lang.String hostname)
context.getHttpServer()..addContext(hostname,context)
.
The call does not alter the original registration of the
context, nor can it change the context path.hostname
- public java.util.List getHosts()
public java.lang.String getContextPath()
public HttpServer getHttpServer()
public java.lang.String getClassPath()
public void setClassPath(java.lang.String classPath)
fileBase
- 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
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
- setClassPaths
public java.lang.ClassLoader getClassLoader()
public void setClassLoader(java.lang.ClassLoader loader)
loader
- public java.lang.String getResourceBase()
public void setResourceBase(java.lang.String resourceBase)
resourceBase
- A URL prefix or directory name.public Resource getResource(java.lang.String path) throws java.io.IOException
path
- A path to be applied to the resource basepublic Resource getBaseResource()
public void setBaseResource(Resource base)
base
- The resourceBase as a Resource instancepublic void setResourceAlias(java.lang.String alias, java.lang.String uri)
alias
- uri
- public java.lang.String getResourceAlias(java.lang.String alias)
public java.lang.String removeResourceAlias(java.lang.String alias)
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 classnamepublic java.lang.String removeErrorPage(java.lang.String error)
public void setHttpServerAccess(boolean access)
access
- public boolean getHttpServerAccess()
public java.util.List getHandlers()
public int getHandlerSize()
public void addHandler(int i, HttpHandler handler)
i
- The position in the handler listhandler
- The handler.public void addHandler(HttpHandler handler)
handler
- public HttpHandler getHandler(int i)
i
- public int getHandlerIndex(HttpHandler handler)
Handler
- instancepublic HttpHandler getHandler(java.lang.Class handlerClass)
handlerClass
- public HttpHandler removeHandler(int i)
i
- public void removeHandler(HttpHandler handler)
public ResourceHandler getResourceHandler()
public SecurityHandler getSecurityHandler()
public void setServingResources(boolean serve)
serve
- If true and there is no ResourceHandler instance in the
context, a ResourceHandler is added. If false, all ResourceHandler
instances are removed from the context.public boolean isServingResources()
public void setRealm(java.lang.String realmName)
realmName
- The name to use to retrieve the actual realm
from the HttpServerpublic void setRealm(java.lang.String realmName, UserRealm realm)
realmName
- The name of the realmrealm
- The realm instance to use, instead of one
retrieved from the HttpServer.public java.lang.String getRealm()
public void addSecurityConstraint(java.lang.String pathSpec, SecurityConstraint sc)
pathSpec
- sc
- public void addAuthConstraint(java.lang.String pathSpec, java.lang.String role)
pathSpec
- Auth
- rolepublic java.util.Map getMimeMap()
public void setMimeMap(java.util.Map mimeMap)
mimeMap
- public java.lang.String getMimeByExtension(java.lang.String filename)
filename
- public void setMimeMapping(java.lang.String extension, java.lang.String type)
extension
- type
- public java.util.Map getEncodingMap()
public void setEncodingMap(java.util.Map encodingMap)
encodingMap
- public java.lang.String getEncodingByMimeType(java.lang.String type)
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 toString()
toString
in class java.lang.Object
public java.lang.String toString(boolean detail)
public void start() throws java.lang.Exception
start
in interface LifeCycle
org.mortbay.util.LifeCycle
java.lang.Exception
- An arbitrary exception may be thrown.public boolean isStarted()
isStarted
in interface LifeCycle
org.mortbay.util.LifeCycle
public void stop() throws java.lang.InterruptedException
stop
in interface LifeCycle
java.lang.InterruptedException
- If interrupted, stop may not have
been called on everything.public void destroy()
destroy
in interface LifeCycle
public boolean isDestroyed()
isDestroyed
in interface LifeCycle
org.mortbay.util.LifeCycle
public void setStatsOn(boolean on)
on
- If true, statistics will be recorded for this context.public boolean getStatsOn()
public void statsReset()
public int getRequests()
public int getResponses1xx()
public int getResponses2xx()
public int getResponses3xx()
public int getResponses4xx()
public int getResponses5xx()
public LogSink getLogSink()
public void setLogSink(LogSink logSink)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |