org.mortbay.jetty.handler
Class ContextHandler
java.lang.Object
org.mortbay.component.AbstractLifeCycle
org.mortbay.jetty.handler.AbstractHandler
org.mortbay.jetty.handler.WrappedHandler
org.mortbay.jetty.handler.ContextHandler
- All Implemented Interfaces:
- LifeCycle, Handler, Attributes
- Direct Known Subclasses:
- WebAppContext
public class ContextHandler
- extends WrappedHandler
- implements Attributes
ContextHandler.
This handler wraps a call to handle by setting the context and
servlet path, plus setting the context classloader.
- Author:
- gregw
__context
private static ThreadLocal __context
_attributes
private Attributes _attributes
_contextAttributes
private Attributes _contextAttributes
_classLoader
private ClassLoader _classLoader
_context
private ContextHandler.Context _context
_contextPath
private String _contextPath
_initParams
private HashMap _initParams
_displayName
private String _displayName
_docRoot
private String _docRoot
_baseResource
private Resource _baseResource
_mimeTypes
private MimeTypes _mimeTypes
_localeEncodingMap
private Map _localeEncodingMap
_welcomeFiles
private String[] _welcomeFiles
_errorHandler
private ErrorHandler _errorHandler
_hosts
private String[] _hosts
_vhosts
private String[] _vhosts
_eventListeners
private EventListener[] _eventListeners
logger
Logger logger
_contextListeners
private Object _contextListeners
_contextAttributeListeners
private Object _contextAttributeListeners
_requestListeners
private Object _requestListeners
_requestAttributeListeners
private Object _requestAttributeListeners
ContextHandler
public ContextHandler()
getCurrentContext
public static ContextHandler.Context getCurrentContext()
- Get the current ServletContext implementation.
This call is only valid during a call to doStart and is available to
nested handlers to access the context.
- Returns:
- ServletContext implementation
setServer
public void setServer(Server server)
- Specified by:
setServer
in interface Handler
- Overrides:
setServer
in class WrappedHandler
setVirtualHosts
public void setVirtualHosts(String[] vhosts)
- Set the virtual hosts for the context.
Only requests that have a matching host header or fully qualified
URL will be passed to that context with a virtual host name.
A context with no virtual host names or a null virtual host name is
available to all requests that are not served by a context with a
matching virtual host name.
- 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.
getVirtualHosts
public String[] getVirtualHosts()
- Get the virtual hosts for the context.
Only requests that have a matching host header or fully qualified
URL will be passed to that context with a virtual host name.
A context with no virtual host names or a null virtual host name is
available to all requests that are not served by a context with a
matching virtual host name.
- 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.
setHosts
public void setHosts(String[] hosts)
- Set the hosts for the context.
Set the real hosts that this context will accept requests for.
If not null or empty, then only requests from server for hosts
in this array are accepted by this context.
getHosts
public String[] getHosts()
- Get the hosts for the context.
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttribute
in interface Attributes
getAttributeNames
public Enumeration getAttributeNames()
- Specified by:
getAttributeNames
in interface Attributes
getAttributes
public Attributes getAttributes()
- Returns:
- Returns the attributes.
getClassLoader
public ClassLoader getClassLoader()
- Returns:
- Returns the classLoader.
getContextPath
public String getContextPath()
- Returns:
- Returns the _contextPath.
getInitParameter
public String getInitParameter(String name)
getInitParameterNames
public Enumeration getInitParameterNames()
getInitParams
public HashMap getInitParams()
- Returns:
- Returns the initParams.
getDisplayName
public String getDisplayName()
getEventListeners
public EventListener[] getEventListeners()
setEventListeners
public void setEventListeners(EventListener[] eventListeners)
doStart
protected void doStart()
throws Exception
- Overrides:
doStart
in class WrappedHandler
- Throws:
Exception
startContext
protected void startContext()
throws Exception
- Throws:
Exception
doStop
protected void doStop()
throws Exception
- Overrides:
doStop
in class WrappedHandler
- Throws:
Exception
handle
public boolean handle(String target,
HttpServletRequest request,
HttpServletResponse response,
int dispatch)
throws IOException,
ServletException
- Description copied from interface:
Handler
- Generic Jetty request handler.
- Specified by:
handle
in interface Handler
- Overrides:
handle
in class WrappedHandler
- Parameters:
target
- The target of the request - either a URI or a name.request
- The request either as the Request
object or a wrapper of that request. The HttpConnection.getCurrentConnection()
method can be used access the Request object if required.response
- The response as the Response
object or a wrapper of that request. The HttpConnection.getCurrentConnection()
method can be used access the Response object if required.dispatch
- The dispatch mode: Handler.REQUEST
, Handler.FORWARD
, Handler.INCLUDE
, Handler.ERROR
- Returns:
- True if the request has been handled
- Throws:
IOException
ServletException
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttribute
in interface Attributes
setAttribute
public void setAttribute(String name,
Object value)
- Specified by:
setAttribute
in interface Attributes
setAttributes
public void setAttributes(Attributes attributes)
- Parameters:
attributes
- The attributes to set.
clearAttributes
public void clearAttributes()
- Specified by:
clearAttributes
in interface Attributes
setClassLoader
public void setClassLoader(ClassLoader classLoader)
- Parameters:
classLoader
- The classLoader to set.
setContextPath
public void setContextPath(String contextPath)
- Parameters:
_contextPath
- The _contextPath to set.
setInitParams
public void setInitParams(HashMap initParams)
- Parameters:
initParams
- The initParams to set.
setDisplayName
public void setDisplayName(String servletContextName)
- Parameters:
servletContextName
- The servletContextName to set.
getBaseResource
public Resource getBaseResource()
- Returns:
- Returns the resourceBase.
getResourceBase
public String getResourceBase()
- Returns:
- Returns the base resource as a string.
setBaseResource
public void setBaseResource(Resource base)
- Parameters:
resourceBase
- The resourceBase to set.
setResourceBase
public void setResourceBase(String resourceBase)
- Parameters:
resourceBase
- The base resource as a string.
getMimeTypes
public MimeTypes getMimeTypes()
- Returns:
- Returns the mimeTypes.
setMimeTypes
public void setMimeTypes(MimeTypes mimeTypes)
- Parameters:
mimeTypes
- The mimeTypes to set.
setWelcomeFiles
public void setWelcomeFiles(String[] files)
getWelcomeFiles
public String[] getWelcomeFiles()
- Returns:
getErrorHandler
public ErrorHandler getErrorHandler()
- Returns:
- Returns the errorHandler.
setErrorHandler
public void setErrorHandler(ErrorHandler errorHandler)
- Parameters:
errorHandler
- The errorHandler to set.
toString
public String toString()
- Overrides:
toString
in class AbstractHandler
loadClass
public Class loadClass(String className)
throws ClassNotFoundException
- Throws:
ClassNotFoundException
addLocaleEncoding
public void addLocaleEncoding(String locale,
String encoding)
getLocaleEncoding
public String getLocaleEncoding(Locale locale)
- Get the character encoding for a locale. The full locale name is first
looked up in the map of encodings. If no encoding is found, then the
locale language is looked up.
- Parameters:
locale
- a Locale
value
- Returns:
- a
String
representing the character encoding for
the locale or null if none found.
getResource
public Resource getResource(String path)
throws MalformedURLException
- Throws:
MalformedURLException
getResourcePaths
public Set getResourcePaths(String path)