org.eclipse.jetty.server.handler
类 ContextHandler

java.lang.Object
  继承者 org.eclipse.jetty.util.component.AbstractLifeCycle
      继承者 org.eclipse.jetty.util.component.AggregateLifeCycle
          继承者 org.eclipse.jetty.server.handler.AbstractHandler
              继承者 org.eclipse.jetty.server.handler.AbstractHandlerContainer
                  继承者 org.eclipse.jetty.server.handler.HandlerWrapper
                      继承者 org.eclipse.jetty.server.handler.ScopedHandler
                          继承者 org.eclipse.jetty.server.handler.ContextHandler
所有已实现的接口:
Handler, HandlerContainer, Server.Graceful, Attributes, Destroyable, Dumpable, LifeCycle
直接已知子类:
HttpSpiContextHandler, MovedContextHandler, ServletContextHandler

public class ContextHandler
extends ScopedHandler
implements Attributes, Server.Graceful

ContextHandler. This handler wraps a call to handle by setting the context and servlet path, plus setting the context classloader.

If the context init parameter "org.eclipse.jetty.server.context.ManagedAttributes" is set to a comma separated list of names, then they are treated as context attribute names, which if set as attributes are passed to the servers Container so that they may be managed with JMX.

The maximum size of a form that can be processed by this context is controlled by the system properties org.eclipse.jetty.server.Request.maxFormKeys and org.eclipse.jetty.server.Request.maxFormContentSize. These can also be configured with setMaxFormContentSize(int) and setMaxFormKeys(int)


嵌套类摘要
static interface ContextHandler.AliasCheck
          Interface to check aliases
static class ContextHandler.ApproveNonExistentDirectoryAliases
          Approve Aliases of a non existent directory.
static class ContextHandler.ApprovePathPrefixAliases
          Approve Aliases with a path prefix.
static class ContextHandler.ApproveSameSuffixAliases
          Approve Aliases with same suffix.
 class ContextHandler.Context
          Context.
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的嵌套类/接口
AbstractLifeCycle.AbstractLifeCycleListener
 
从接口 org.eclipse.jetty.util.component.LifeCycle 继承的嵌套类/接口
LifeCycle.Listener
 
字段摘要
protected  ContextHandler.Context _scontext
           
static String MANAGED_ATTRIBUTES
          If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name.
 
从类 org.eclipse.jetty.server.handler.ScopedHandler 继承的字段
_nextScope, _outerScope
 
从类 org.eclipse.jetty.server.handler.HandlerWrapper 继承的字段
_handler
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的字段
_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
 
构造方法摘要
  ContextHandler()
           
protected ContextHandler(ContextHandler.Context context)
           
  ContextHandler(HandlerContainer parent, String contextPath)
           
  ContextHandler(String contextPath)
           
 
方法摘要
 void addAliasCheck(ContextHandler.AliasCheck check)
          Add an AliasCheck instance to possibly permit aliased resources
 void addEventListener(EventListener listener)
          Add a context event listeners.
 void addLocaleEncoding(String locale, String encoding)
           
 void addVirtualHosts(String[] virtualHosts)
          Either set virtual hosts or add to an existing set of virtual hosts.
 void callContextDestroyed(ServletContextListener l, ServletContextEvent e)
           
 void callContextInitialized(ServletContextListener l, ServletContextEvent e)
           
 boolean checkContext(String target, Request baseRequest, HttpServletResponse response)
           
 void checkManagedAttribute(String name, Object value)
           
 void clearAttributes()
           
 void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
           
 void doScope(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
           
protected  void doStart()
          Start the managed lifecycle beans in the order they were added.
protected  void doStop()
          Stop the joined lifecycle beans in the reverse order they were added.
 void dump(Appendable out, String indent)
           
 List<ContextHandler.AliasCheck> getAliasChecks()
           
 boolean getAllowNullPathInfo()
           
 Object getAttribute(String name)
           
 Enumeration getAttributeNames()
           
 Attributes getAttributes()
           
 Resource getBaseResource()
           
 ClassLoader getClassLoader()
           
 String getClassPath()
          Make best effort to extract a file classpath from the context classloader
 String[] getConnectorNames()
           
 String getContextPath()
           
static ContextHandler.Context getCurrentContext()
          Get the current ServletContext implementation.
 String getDisplayName()
           
 ErrorHandler getErrorHandler()
           
 EventListener[] getEventListeners()
           
 String getInitParameter(String name)
           
 Enumeration getInitParameterNames()
           
 Map<String,String> getInitParams()
           
 String getLocaleEncoding(Locale locale)
          Get the character encoding for a locale.
 String getLocaleEncoding(String locale)
           
 Logger getLogger()
           
 int getMaxFormContentSize()
           
 int getMaxFormKeys()
           
 MimeTypes getMimeTypes()
           
 String[] getProtectedTargets()
           
 Resource getResource(String path)
           
 String getResourceBase()
           
 Set<String> getResourcePaths(String path)
           
 ContextHandler.Context getServletContext()
           
 String[] getVirtualHosts()
          Get the virtual hosts for the context.
 String[] getWelcomeFiles()
           
 void handle(Runnable runnable)
           
 boolean isAliases()
           
 boolean isAvailable()
           
 boolean isCompactPath()
           
 boolean isProtectedTarget(String target)
          Check the target.
 boolean isShutdown()
           
 Class<?> loadClass(String className)
           
 Resource newResource(String urlOrPath)
          Convert a URL or path to a Resource.
 Resource newResource(URL url)
          Convert URL to Resource wrapper for Resource.newResource(URL) enables extensions to provide alternate resource implementations.
 void removeAttribute(String name)
           
 void removeVirtualHosts(String[] virtualHosts)
          Removes an array of virtual host entries, if this removes all entries the _vhosts will be set to null
 void restrictEventListener(EventListener listener)
          Apply any necessary restrictions on a programmatically added listener.
 void setAliases(boolean aliases)
           
 void setAllowNullPathInfo(boolean allowNullPathInfo)
           
 void setAttribute(String name, Object value)
           
 void setAttributes(Attributes attributes)
           
 void setAvailable(boolean available)
          Set Available status.
 void setBaseResource(Resource base)
           
 void setClassLoader(ClassLoader classLoader)
           
 void setCompactPath(boolean compactPath)
           
 void setConnectorNames(String[] connectors)
          Set the names of accepted connectors.
 void setContextPath(String contextPath)
           
 void setDisplayName(String servletContextName)
           
 void setErrorHandler(ErrorHandler errorHandler)
           
 void setEventListeners(EventListener[] eventListeners)
          Set the context event listeners.
 String setInitParameter(String name, String value)
           
 void setLogger(Logger logger)
           
 void setManagedAttribute(String name, Object value)
           
 void setMaxFormContentSize(int maxSize)
          Set the maximum size of a form post, to protect against DOS attacks from large forms.
 void setMaxFormKeys(int max)
          Set the maximum number of form Keys to protect against DOS attack from crafted hash keys.
 void setMimeTypes(MimeTypes mimeTypes)
           
 void setProtectedTargets(String[] targets)
           
 void setResourceBase(String resourceBase)
           
 void setServer(Server server)
           
 void setShutdown(boolean shutdown)
          Set shutdown status.
 void setVirtualHosts(String[] vhosts)
          Set the virtual hosts for the context.
 void setWelcomeFiles(String[] files)
           
protected  void startContext()
          Extensible startContext. this method is called from doStart() instead of a call to super.doStart().
 String toString()
           
 
从类 org.eclipse.jetty.server.handler.ScopedHandler 继承的方法
handle, never, nextHandle, nextScope
 
从类 org.eclipse.jetty.server.handler.HandlerWrapper 继承的方法
destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler
 
从类 org.eclipse.jetty.server.handler.AbstractHandlerContainer 继承的方法
expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass
 
从类 org.eclipse.jetty.server.handler.AbstractHandler 继承的方法
dumpThis, getServer
 
从类 org.eclipse.jetty.util.component.AggregateLifeCycle 继承的方法
addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage
 
从类 org.eclipse.jetty.util.component.AbstractLifeCycle 继承的方法
addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
从接口 org.eclipse.jetty.server.Handler 继承的方法
destroy, getServer, handle
 
从接口 org.eclipse.jetty.util.component.LifeCycle 继承的方法
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
 

字段详细信息

MANAGED_ATTRIBUTES

public static final String MANAGED_ATTRIBUTES
If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name. Any other context attributes that are set with a name from this list will result in a call to setManagedAttribute(String, Object), which typically initiates the creation of a JMX MBean for the attribute value.

另请参见:
常量字段值

_scontext

protected ContextHandler.Context _scontext
构造方法详细信息

ContextHandler

public ContextHandler()

ContextHandler

protected ContextHandler(ContextHandler.Context context)

ContextHandler

public ContextHandler(String contextPath)

ContextHandler

public ContextHandler(HandlerContainer parent,
                      String contextPath)
方法详细信息

getCurrentContext

public static ContextHandler.Context getCurrentContext()
Get the current ServletContext implementation.

返回:
ServletContext implementation

dump

public void dump(Appendable out,
                 String indent)
          throws IOException
指定者:
接口 Dumpable 中的 dump
覆盖:
AbstractHandlerContainer 中的 dump
抛出:
IOException

getServletContext

public ContextHandler.Context getServletContext()

getAllowNullPathInfo

public boolean getAllowNullPathInfo()
返回:
the allowNullPathInfo true if /context is not redirected to /context/

setAllowNullPathInfo

public void setAllowNullPathInfo(boolean allowNullPathInfo)
参数:
allowNullPathInfo - true if /context is not redirected to /context/

setServer

public void setServer(Server server)
指定者:
接口 Handler 中的 setServer
覆盖:
HandlerWrapper 中的 setServer

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.

参数:
vhosts - 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 be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.

addVirtualHosts

public void addVirtualHosts(String[] virtualHosts)
Either set virtual hosts or add to an existing set of virtual hosts.

参数:
virtualHosts - 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 be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.

removeVirtualHosts

public void removeVirtualHosts(String[] virtualHosts)
Removes an array of virtual host entries, if this removes all entries the _vhosts will be set to null

参数:
virtualHosts - 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 be String representation of IP addresses. Host names may start with '*.' to wildcard one level of names.

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.

返回:
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. Host names may start with '*.' to wildcard one level of names.

getConnectorNames

public String[] getConnectorNames()
返回:
an array of connector names that this context will accept a request from.

setConnectorNames

public void setConnectorNames(String[] connectors)
Set the names of accepted connectors. Names are either "host:port" or a specific configured name for a connector.

参数:
connectors - If non null, an array of connector names that this context will accept a request from.

getAttribute

public Object getAttribute(String name)
指定者:
接口 Attributes 中的 getAttribute

getAttributeNames

public Enumeration getAttributeNames()
指定者:
接口 Attributes 中的 getAttributeNames

getAttributes

public Attributes getAttributes()
返回:
Returns the attributes.

getClassLoader

public ClassLoader getClassLoader()
返回:
Returns the classLoader.

getClassPath

public String getClassPath()
Make best effort to extract a file classpath from the context classloader

返回:
Returns the classLoader.

getContextPath

public String getContextPath()
返回:
Returns the _contextPath.

getInitParameter

public String getInitParameter(String name)

setInitParameter

public String setInitParameter(String name,
                               String value)

getInitParameterNames

public Enumeration getInitParameterNames()

getInitParams

public Map<String,String> getInitParams()
返回:
Returns the initParams.

getDisplayName

public String getDisplayName()

getEventListeners

public EventListener[] getEventListeners()

setEventListeners

public void setEventListeners(EventListener[] eventListeners)
Set the context event listeners.

参数:
eventListeners - the event listeners
另请参见:
ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener

addEventListener

public void addEventListener(EventListener listener)
Add a context event listeners.

另请参见:
ServletContextListener, ServletContextAttributeListener, ServletRequestListener, ServletRequestAttributeListener

restrictEventListener

public void restrictEventListener(EventListener listener)
Apply any necessary restrictions on a programmatically added listener. Superclasses should implement.

参数:
listener -

isShutdown

public boolean isShutdown()
返回:
true if this context is accepting new requests

setShutdown

public void setShutdown(boolean shutdown)
Set shutdown status. This field allows for graceful shutdown of a context. A started context may be put into non accepting state so that existing requests can complete, but no new requests are accepted.

指定者:
接口 Server.Graceful 中的 setShutdown
参数:
shutdown - true if this context is (not?) accepting new requests

isAvailable

public boolean isAvailable()
返回:
false if this context is unavailable (sends 503)

setAvailable

public void setAvailable(boolean available)
Set Available status.


getLogger

public Logger getLogger()

setLogger

public void setLogger(Logger logger)

doStart

protected void doStart()
                throws Exception
从类 AggregateLifeCycle 复制的描述
Start the managed lifecycle beans in the order they were added.

覆盖:
ScopedHandler 中的 doStart
抛出:
Exception
另请参见:
HandlerWrapper.doStart()

startContext

protected void startContext()
                     throws Exception
Extensible startContext. this method is called from doStart() instead of a call to super.doStart(). This allows derived classes to insert additional handling (Eg configuration) before the call to super.doStart by this method will start contained handlers.

抛出:
Exception
另请参见:
ContextHandler.Context

callContextInitialized

public void callContextInitialized(ServletContextListener l,
                                   ServletContextEvent e)

callContextDestroyed

public void callContextDestroyed(ServletContextListener l,
                                 ServletContextEvent e)

doStop

protected void doStop()
               throws Exception
从类 AggregateLifeCycle 复制的描述
Stop the joined lifecycle beans in the reverse order they were added.

覆盖:
HandlerWrapper 中的 doStop
抛出:
Exception
另请参见:
AbstractLifeCycle.doStart()

checkContext

public boolean checkContext(String target,
                            Request baseRequest,
                            HttpServletResponse response)
                     throws IOException,
                            ServletException
抛出:
IOException
ServletException

doScope

public void doScope(String target,
                    Request baseRequest,
                    HttpServletRequest request,
                    HttpServletResponse response)
             throws IOException,
                    ServletException
指定者:
ScopedHandler 中的 doScope
抛出:
IOException
ServletException
另请参见:
ScopedHandler.doScope(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

doHandle

public void doHandle(String target,
                     Request baseRequest,
                     HttpServletRequest request,
                     HttpServletResponse response)
              throws IOException,
                     ServletException
指定者:
ScopedHandler 中的 doHandle
抛出:
IOException
ServletException
另请参见:
ScopedHandler.doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)

handle

public void handle(Runnable runnable)

isProtectedTarget

public boolean isProtectedTarget(String target)
Check the target. Called by ScopedHandler.handle(String, Request, HttpServletRequest, HttpServletResponse) when a target within a context is determined. If the target is protected, 404 is returned.


setProtectedTargets

public void setProtectedTargets(String[] targets)

getProtectedTargets

public String[] getProtectedTargets()

removeAttribute

public void removeAttribute(String name)
指定者:
接口 Attributes 中的 removeAttribute

setAttribute

public void setAttribute(String name,
                         Object value)
指定者:
接口 Attributes 中的 setAttribute

setAttributes

public void setAttributes(Attributes attributes)
参数:
attributes - The attributes to set.

clearAttributes

public void clearAttributes()
指定者:
接口 Attributes 中的 clearAttributes

checkManagedAttribute

public void checkManagedAttribute(String name,
                                  Object value)

setManagedAttribute

public void setManagedAttribute(String name,
                                Object value)

setClassLoader

public void setClassLoader(ClassLoader classLoader)
参数:
classLoader - The classLoader to set.

setContextPath

public void setContextPath(String contextPath)
参数:
contextPath - The _contextPath to set.

setDisplayName

public void setDisplayName(String servletContextName)
参数:
servletContextName - The servletContextName to set.

getBaseResource

public Resource getBaseResource()
返回:
Returns the resourceBase.

getResourceBase

public String getResourceBase()
返回:
Returns the base resource as a string.

setBaseResource

public void setBaseResource(Resource base)
参数:
base - The resourceBase to set.

setResourceBase

public void setResourceBase(String resourceBase)
参数:
resourceBase - The base resource as a string.

isAliases

public boolean isAliases()
返回:
True if aliases are allowed

setAliases

public void setAliases(boolean aliases)
参数:
aliases - aliases are allowed

getMimeTypes

public MimeTypes getMimeTypes()
返回:
Returns the mimeTypes.

setMimeTypes

public void setMimeTypes(MimeTypes mimeTypes)
参数:
mimeTypes - The mimeTypes to set.

setWelcomeFiles

public void setWelcomeFiles(String[] files)

getWelcomeFiles

public String[] getWelcomeFiles()
返回:
The names of the files which the server should consider to be welcome files in this context.
另请参见:
The Servlet Specification, setWelcomeFiles(java.lang.String[])

getErrorHandler

public ErrorHandler getErrorHandler()
返回:
Returns the errorHandler.

setErrorHandler

public void setErrorHandler(ErrorHandler errorHandler)
参数:
errorHandler - The errorHandler to set.

getMaxFormContentSize

public int getMaxFormContentSize()

setMaxFormContentSize

public void setMaxFormContentSize(int maxSize)
Set the maximum size of a form post, to protect against DOS attacks from large forms.

参数:
maxSize -

getMaxFormKeys

public int getMaxFormKeys()

setMaxFormKeys

public void setMaxFormKeys(int max)
Set the maximum number of form Keys to protect against DOS attack from crafted hash keys.

参数:
max -

isCompactPath

public boolean isCompactPath()
返回:
True if URLs are compacted to replace multiple '/'s with a single '/'

setCompactPath

public void setCompactPath(boolean compactPath)
参数:
compactPath - True if URLs are compacted to replace multiple '/'s with a single '/'

toString

public String toString()
覆盖:
Object 中的 toString

loadClass

public Class<?> loadClass(String className)
                   throws ClassNotFoundException
抛出:
ClassNotFoundException

addLocaleEncoding

public void addLocaleEncoding(String locale,
                              String encoding)

getLocaleEncoding

public String getLocaleEncoding(String locale)

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.

参数:
locale - a Locale value
返回:
a String representing the character encoding for the locale or null if none found.

getResource

public Resource getResource(String path)
                     throws MalformedURLException
抛出:
MalformedURLException

newResource

public Resource newResource(URL url)
                     throws IOException
Convert URL to Resource wrapper for Resource.newResource(URL) enables extensions to provide alternate resource implementations.

抛出:
IOException

newResource

public Resource newResource(String urlOrPath)
                     throws IOException
Convert a URL or path to a Resource. The default implementation is a wrapper for Resource.newResource(String).

参数:
urlOrPath - The URL or path to convert
返回:
The Resource for the URL/path
抛出:
IOException - The Resource could not be created.

getResourcePaths

public Set<String> getResourcePaths(String path)

addAliasCheck

public void addAliasCheck(ContextHandler.AliasCheck check)
Add an AliasCheck instance to possibly permit aliased resources

参数:
check - The alias checker

getAliasChecks

public List<ContextHandler.AliasCheck> getAliasChecks()
返回:
Mutable list of Alias checks


Copyright © 2013. All Rights Reserved.