Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.eclipse.jetty.server.handler
Class ContextHandler

    java.lang.Object
      org.eclipse.jetty.util.component.AbstractLifeCycle
          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

All Implemented Interfaces:
  Handler, HandlerContainer, Server.Graceful, Attributes, LifeCycle

Direct Known Subclasses:
  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.

Nested Class Summary
`class` | `ContextHandler.Context` Context.

Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`AbstractLifeCycle.AbstractLifeCycleListener`

Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
`LifeCycle.Listener`

Field Summary
`protected ContextHandler.Context` | `_scontext`
`static java.lang.String` | `MANAGED_ATTRIBUTES` If a context attribute with this name is set, it is interpreted as a comma separated list of attribute name.

Fields inherited from class org.eclipse.jetty.server.handler.ScopedHandler
`_nextScope, _outerScope`

Fields inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
`_handler`

Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

Constructor Summary
`` | `ContextHandler()`
`protected` | `ContextHandler(ContextHandler.Context context)`
`` | `ContextHandler(HandlerContainer parent, java.lang.String contextPath)`
`` | `ContextHandler(java.lang.String contextPath)`

Method Summary
`void` | `addEventListener(java.util.EventListener listener)` Add a context event listeners.
`void` | `addLocaleEncoding(java.lang.String locale, java.lang.String encoding)`
`void` | `callContextDestroyed(ServletContextListener l, ServletContextEvent e)`
`void` | `callContextInitialized(ServletContextListener l, ServletContextEvent e)`
`boolean` | `checkContext(java.lang.String target, Request baseRequest, HttpServletResponse response)`
`void` | `checkManagedAttribute(java.lang.String name, java.lang.Object value)`
`void` | `clearAttributes()`
`void` | `doHandle(java.lang.String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)`
`void` | `doScope(java.lang.String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)`
`protected void` | `doStart()`
`protected void` | `doStop()`
`protected void` | `dump(java.lang.Appendable out, java.lang.String indent)`
`boolean` | `getAllowNullPathInfo()`
`java.lang.Object` | `getAttribute(java.lang.String name)`
`java.util.Enumeration` | `getAttributeNames()`
`Attributes` | `getAttributes()`
`Resource` | `getBaseResource()`
`java.lang.ClassLoader` | `getClassLoader()`
`java.lang.String` | `getClassPath()` Make best effort to extract a file classpath from the context classloader
`java.lang.String[]` | `getConnectorNames()`
`java.lang.String` | `getContextPath()`
`static ContextHandler.Context` | `getCurrentContext()` Get the current ServletContext implementation.
`java.lang.String` | `getDisplayName()`
`ErrorHandler` | `getErrorHandler()`
`java.util.EventListener[]` | `getEventListeners()`
`java.lang.String` | `getInitParameter(java.lang.String name)`
`java.util.Enumeration` | `getInitParameterNames()`
`java.util.Map<java.lang.String,java.lang.String>` | `getInitParams()`
`java.lang.String` | `getLocaleEncoding(java.util.Locale locale)` Get the character encoding for a locale.
`java.lang.String` | `getLocaleEncoding(java.lang.String locale)`
`Logger` | `getLogger()`
`int` | `getMaxFormContentSize()`
`MimeTypes` | `getMimeTypes()`
`Resource` | `getResource(java.lang.String path)`
`java.lang.String` | `getResourceBase()`
`java.util.Set<java.lang.String>` | `getResourcePaths(java.lang.String path)`
`ContextHandler.Context` | `getServletContext()`
`java.lang.String[]` | `getVirtualHosts()` Get the virtual hosts for the context.
`java.lang.String[]` | `getWelcomeFiles()`
`void` | `handle(java.lang.Runnable runnable)`
`boolean` | `isAliases()`
`boolean` | `isAvailable()`
`boolean` | `isCompactPath()`
`protected boolean` | `isProtectedTarget(java.lang.String target)` Check the target.
`boolean` | `isShutdown()`
`java.lang.Class<?>` | `loadClass(java.lang.String className)`
`Resource` | `newResource(java.lang.String urlOrPath)` Convert a URL or path to a Resource.
`Resource` | `newResource(java.net.URL url)` Convert URL to Resource wrapper for `Resource.newResource(URL)` enables extensions to provide alternate resource implementations.
`void` | `removeAttribute(java.lang.String name)`
`void` | `restrictEventListener(java.util.EventListener listener)` Apply any necessary restrictions on a programmatically added listener.
`void` | `setAliases(boolean aliases)`
`void` | `setAllowNullPathInfo(boolean allowNullPathInfo)`
`void` | `setAttribute(java.lang.String name, java.lang.Object value)`
`void` | `setAttributes(Attributes attributes)`
`void` | `setAvailable(boolean available)` Set Available status.
`void` | `setBaseResource(Resource base)`
`void` | `setClassLoader(java.lang.ClassLoader classLoader)`
`void` | `setCompactPath(boolean compactPath)`
`void` | `setConnectorNames(java.lang.String[] connectors)` Set the names of accepted connectors.
`void` | `setContextPath(java.lang.String contextPath)`
`void` | `setDisplayName(java.lang.String servletContextName)`
`void` | `setErrorHandler(ErrorHandler errorHandler)`
`void` | `setEventListeners(java.util.EventListener[] eventListeners)` Set the context event listeners.
`void` | `setLogger(Logger logger)`
`void` | `setManagedAttribute(java.lang.String name, java.lang.Object value)`
`void` | `setMaxFormContentSize(int maxSize)`
`void` | `setMimeTypes(MimeTypes mimeTypes)`
`void` | `setResourceBase(java.lang.String resourceBase)`
`void` | `setServer(Server server)`
`void` | `setShutdown(boolean shutdown)` Set shutdown status.
`void` | `setVirtualHosts(java.lang.String[] vhosts)` Set the virtual hosts for the context.
`void` | `setWelcomeFiles(java.lang.String[] files)`
`protected void` | `startContext()` Extensible startContext.
`java.lang.String` | `toString()`

Methods inherited from class org.eclipse.jetty.server.handler.ScopedHandler
`handle, never, nextHandle, nextScope`

Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper
`expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler`

Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer
`dumpHandlers, expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler
`destroy, dump, dump, getServer`

Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
`addLifeCycleListener, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.eclipse.jetty.server.Handler
`destroy, getServer, handle`

Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Field Detail

### MANAGED_ATTRIBUTES

    public static final java.lang.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.

  See Also:
    Constant Field Values

### _scontext

    protected ContextHandler.Context _scontext

Constructor Detail

### ContextHandler

    public ContextHandler()

### ContextHandler

    protected ContextHandler(ContextHandler.Context context)

### ContextHandler

    public ContextHandler(java.lang.String contextPath)

### ContextHandler

    public ContextHandler(HandlerContainer parent,
                          java.lang.String contextPath)

Method Detail

### getCurrentContext

    public static ContextHandler.Context getCurrentContext()

  Get the current ServletContext implementation.

  Returns:
    ServletContext implementation

### dump

    protected void dump(java.lang.Appendable out,
                        java.lang.String indent)
                 throws java.io.IOException

  Overrides:
    `dump` in class `AbstractHandlerContainer`
  Throws:
    `java.io.IOException`

### getServletContext

    public ContextHandler.Context getServletContext()

### getAllowNullPathInfo

    public boolean getAllowNullPathInfo()

  Returns:
    the allowNullPathInfo true if /context is not redirected to /context/

### setAllowNullPathInfo

    public void setAllowNullPathInfo(boolean allowNullPathInfo)

  Parameters:
    `allowNullPathInfo` - true if /context is not redirected to /context/

### setServer

    public void setServer(Server server)

  Specified by:
    `setServer` in interface `Handler`
  Overrides:
    `setServer` in class `HandlerWrapper`

### setVirtualHosts

    public void setVirtualHosts(java.lang.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:
    `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.

### getVirtualHosts

    public java.lang.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. Host names may start with '*.' to wildcard one level of names.

### getConnectorNames

    public java.lang.String[] getConnectorNames()

  Returns:
    an array of connector names that this context will accept a request from.

### setConnectorNames

    public void setConnectorNames(java.lang.String[] connectors)

  Set the names of accepted connectors. Names are either "host:port" or a specific configured name for a connector.

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

### getAttribute

    public java.lang.Object getAttribute(java.lang.String name)

  Specified by:
    `getAttribute` in interface `Attributes`

### getAttributeNames

    public java.util.Enumeration getAttributeNames()

  Specified by:
    `getAttributeNames` in interface `Attributes`

### getAttributes

    public Attributes getAttributes()

  Returns:
    Returns the attributes.

### getClassLoader

    public java.lang.ClassLoader getClassLoader()

  Returns:
    Returns the classLoader.

### getClassPath

    public java.lang.String getClassPath()

  Make best effort to extract a file classpath from the context classloader

  Returns:
    Returns the classLoader.

### getContextPath

    public java.lang.String getContextPath()

  Returns:
    Returns the _contextPath.

### getInitParameter

    public java.lang.String getInitParameter(java.lang.String name)

### getInitParameterNames

    public java.util.Enumeration getInitParameterNames()

### getInitParams

    public java.util.Map<java.lang.String,java.lang.String> getInitParams()

  Returns:
    Returns the initParams.

### getDisplayName

    public java.lang.String getDisplayName()

### getEventListeners

    public java.util.EventListener[] getEventListeners()

### setEventListeners

    public void setEventListeners(java.util.EventListener[] eventListeners)

  Set the context event listeners.

  Parameters:
    `eventListeners` - the event listeners
  See Also:
    `ServletContextListener`, `ServletContextAttributeListener`, `ServletRequestListener`, `ServletRequestAttributeListener`

### addEventListener

    public void addEventListener(java.util.EventListener listener)

  Add a context event listeners.

  See Also:
    `ServletContextListener`, `ServletContextAttributeListener`, `ServletRequestListener`, `ServletRequestAttributeListener`

### restrictEventListener

    public void restrictEventListener(java.util.EventListener listener)

  Apply any necessary restrictions on a programmatically added listener. Superclasses should implement.

  Parameters:
    `listener` -

### isShutdown

    public boolean isShutdown()

  Returns:
    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.

  Specified by:
    `setShutdown` in interface `Server.Graceful`
  Parameters:
    `shutdown` - true if this context is (not?) accepting new requests

### isAvailable

    public boolean isAvailable()

  Returns:
    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 java.lang.Exception

  Overrides:
    `doStart` in class `ScopedHandler`
  Throws:
    `java.lang.Exception`
  See Also:
    `HandlerWrapper.doStart()`

### startContext

    protected void startContext()
                         throws java.lang.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.

  Throws:
    `java.lang.Exception`
  See Also:
    `ContextHandler.Context`

### callContextInitialized

    public void callContextInitialized(ServletContextListener l,
                                       ServletContextEvent e)

### callContextDestroyed

    public void callContextDestroyed(ServletContextListener l,
                                     ServletContextEvent e)

### doStop

    protected void doStop()
                   throws java.lang.Exception

  Overrides:
    `doStop` in class `HandlerWrapper`
  Throws:
    `java.lang.Exception`

### checkContext

    public boolean checkContext(java.lang.String target,
                                Request baseRequest,
                                HttpServletResponse response)
                         throws java.io.IOException,
                                ServletException

  Throws:
    `java.io.IOException`
    `ServletException`

### doScope

    public void doScope(java.lang.String target,
                        Request baseRequest,
                        HttpServletRequest request,
                        HttpServletResponse response)
                 throws java.io.IOException,
                        ServletException

  Specified by:
    `doScope` in class `ScopedHandler`
  Throws:
    `java.io.IOException`
    `ServletException`
  See Also:
    `ScopedHandler.doScope(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)`

### doHandle

    public void doHandle(java.lang.String target,
                         Request baseRequest,
                         HttpServletRequest request,
                         HttpServletResponse response)
                  throws java.io.IOException,
                         ServletException

  Specified by:
    `doHandle` in class `ScopedHandler`
  Throws:
    `java.io.IOException`
    `ServletException`
  See Also:
    `ScopedHandler.doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)`

### handle

    public void handle(java.lang.Runnable runnable)

### isProtectedTarget

    protected boolean isProtectedTarget(java.lang.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. The default implementation always returns false.

### removeAttribute

    public void removeAttribute(java.lang.String name)

  Specified by:
    `removeAttribute` in interface `Attributes`

### setAttribute

    public void setAttribute(java.lang.String name,
                             java.lang.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`

### checkManagedAttribute

    public void checkManagedAttribute(java.lang.String name,
                                      java.lang.Object value)

### setManagedAttribute

    public void setManagedAttribute(java.lang.String name,
                                    java.lang.Object value)

### setClassLoader

    public void setClassLoader(java.lang.ClassLoader classLoader)

  Parameters:
    `classLoader` - The classLoader to set.

### setContextPath

    public void setContextPath(java.lang.String contextPath)

  Parameters:
    `contextPath` - The _contextPath to set.

### setDisplayName

    public void setDisplayName(java.lang.String servletContextName)

  Parameters:
    `servletContextName` - The servletContextName to set.

### getBaseResource

    public Resource getBaseResource()

  Returns:
    Returns the resourceBase.

### getResourceBase

    public java.lang.String getResourceBase()

  Returns:
    Returns the base resource as a string.

### setBaseResource

    public void setBaseResource(Resource base)

  Parameters:
    `base` - The resourceBase to set.

### setResourceBase

    public void setResourceBase(java.lang.String resourceBase)

  Parameters:
    `resourceBase` - The base resource as a string.

### isAliases

    public boolean isAliases()

  Returns:
    True if aliases are allowed

### setAliases

    public void setAliases(boolean aliases)

  Parameters:
    `aliases` - aliases are allowed

### getMimeTypes

    public MimeTypes getMimeTypes()

  Returns:
    Returns the mimeTypes.

### setMimeTypes

    public void setMimeTypes(MimeTypes mimeTypes)

  Parameters:
    `mimeTypes` - The mimeTypes to set.

### setWelcomeFiles

    public void setWelcomeFiles(java.lang.String[] files)

### getWelcomeFiles

    public java.lang.String[] getWelcomeFiles()

  Returns:
    The names of the files which the server should consider to be welcome files in this context.
  See Also:
    The Servlet Specification, `setWelcomeFiles(java.lang.String[])`

### getErrorHandler

    public ErrorHandler getErrorHandler()

  Returns:
    Returns the errorHandler.

### setErrorHandler

    public void setErrorHandler(ErrorHandler errorHandler)

  Parameters:
    `errorHandler` - The errorHandler to set.

### getMaxFormContentSize

    public int getMaxFormContentSize()

### setMaxFormContentSize

    public void setMaxFormContentSize(int maxSize)

### isCompactPath

    public boolean isCompactPath()

  Returns:
    True if URLs are compacted to replace multiple '/'s with a single '/'

### setCompactPath

    public void setCompactPath(boolean compactPath)

  Parameters:
    `compactPath` - True if URLs are compacted to replace multiple '/'s with a single '/'

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `AbstractHandler`

### loadClass

    public java.lang.Class<?> loadClass(java.lang.String className)
                                 throws java.lang.ClassNotFoundException

  Throws:
    `java.lang.ClassNotFoundException`

### addLocaleEncoding

    public void addLocaleEncoding(java.lang.String locale,
                                  java.lang.String encoding)

### getLocaleEncoding

    public java.lang.String getLocaleEncoding(java.util.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.

### getLocaleEncoding

    public java.lang.String getLocaleEncoding(java.lang.String locale)

### getResource

    public Resource getResource(java.lang.String path)
                         throws java.net.MalformedURLException

  Throws:
    `java.net.MalformedURLException`

### newResource

    public Resource newResource(java.net.URL url)
                         throws java.io.IOException

  Convert URL to Resource wrapper for `Resource.newResource(URL)` enables extensions to provide alternate resource implementations.

  Throws:
    `java.io.IOException`

### newResource

    public Resource newResource(java.lang.String urlOrPath)
                         throws java.io.IOException

  Convert a URL or path to a Resource. The default implementation is a wrapper for `Resource.newResource(String)`.

  Parameters:
    `urlOrPath` - The URL or path to convert
  Returns:
    The Resource for the URL/path
  Throws:
    `java.io.IOException` - The Resource could not be created.

### getResourcePaths

    public java.util.Set<java.lang.String> getResourcePaths(java.lang.String path)

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.