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.mortbay.jetty.handler
Class ContextHandler

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.handler.AbstractHandler
              org.mortbay.jetty.handler.AbstractHandlerContainer
                  org.mortbay.jetty.handler.HandlerWrapper
                      org.mortbay.jetty.handler.ContextHandler

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

Direct Known Subclasses:
  Context, MovedContextHandler

    public class ContextHandler

extends HandlerWrapper
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.mortbay.jetty.servlet.ManagedAttributes" is set to a coma 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.

Author:
  gregw

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

Nested classes/interfaces inherited from interface org.mortbay.component.LifeCycle
`LifeCycle.Listener`

Field Summary
`protected ContextHandler.SContext` | `_scontext`
`static String` | `MANAGED_ATTRIBUTES`

Fields inherited from class org.mortbay.jetty.handler.AbstractHandler
`_string`

Fields inherited from class org.mortbay.component.AbstractLifeCycle
`_listeners`

Fields inherited from interface org.mortbay.jetty.Handler
`ALL, DEFAULT, ERROR, FORWARD, INCLUDE, REQUEST`

Constructor Summary
`` | `ContextHandler()`
`protected` | `ContextHandler(ContextHandler.SContext context)`
`` | `ContextHandler(HandlerContainer parent, String contextPath)`
`` | `ContextHandler(String contextPath)`

Method Summary
`void` | `addEventListener(EventListener listener)`
`void` | `addLocaleEncoding(String locale, String encoding)`
`void` | `clearAttributes()`
`protected void` | `doStart()`
`protected void` | `doStop()`
`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.SContext` | `getCurrentContext()` Get the current ServletContext implementation.
`String` | `getDisplayName()`
`ErrorHandler` | `getErrorHandler()`
`EventListener[]` | `getEventListeners()`
`String[]` | `getHosts()` Deprecated.
`String` | `getInitParameter(String name)`
`Enumeration` | `getInitParameterNames()`
`Map` | `getInitParams()`
`String` | `getLocaleEncoding(Locale locale)` Get the character encoding for a locale.
`int` | `getMaxFormContentSize()`
`MimeTypes` | `getMimeTypes()`
`Resource` | `getResource(String path)`
`String` | `getResourceBase()`
`Set` | `getResourcePaths(String path)`
`ContextHandler.SContext` | `getServletContext()`
`String[]` | `getVirtualHosts()` Get the virtual hosts for the context.
`String[]` | `getWelcomeFiles()`
`void` | `handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch)` Handle a request.
`boolean` | `isCompactPath()`
`protected boolean` | `isProtectedTarget(String target)` Check the target.
`boolean` | `isShutdown()`
`Class` | `loadClass(String className)`
`void` | `removeAttribute(String name)`
`void` | `setAllowNullPathInfo(boolean allowNullPathInfo)`
`void` | `setAttribute(String name, Object value)`
`void` | `setAttributes(Attributes attributes)`
`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)`
`void` | `setHosts(String[] hosts)` Deprecated. use `setConnectorNames(String[])`
`void` | `setInitParams(Map initParams)`
`void` | `setMaxFormContentSize(int maxSize)`
`void` | `setMimeTypes(MimeTypes mimeTypes)`
`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()`
`String` | `toString()`

Methods inherited from class org.mortbay.jetty.handler.HandlerWrapper
`addHandler, expandChildren, getHandler, removeHandler, setHandler`

Methods inherited from class org.mortbay.jetty.handler.AbstractHandlerContainer
`expandHandler, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

Methods inherited from class org.mortbay.jetty.handler.AbstractHandler
`destroy, getServer`

Methods inherited from class org.mortbay.component.AbstractLifeCycle
`addLifeCycleListener, 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.mortbay.component.LifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Field Detail

### MANAGED_ATTRIBUTES

    public static final String MANAGED_ATTRIBUTES

See Also:
  Constant Field Values

### _scontext

    protected ContextHandler.SContext _scontext

Constructor Detail

### ContextHandler

    public ContextHandler()

### ContextHandler

    protected ContextHandler(ContextHandler.SContext context)

### ContextHandler

    public ContextHandler(String contextPath)

### ContextHandler

    public ContextHandler(HandlerContainer parent,
                          String contextPath)

Method Detail

### getCurrentContext

    public static ContextHandler.SContext 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

### getServletContext

    public ContextHandler.SContext 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(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 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.

### setHosts

    public void setHosts(String[] hosts)

  Deprecated. use `setConnectorNames(String[])`

### getHosts

    public String[] getHosts()

  Deprecated.

  Get the hosts for the context.

### getConnectorNames

    public String[] getConnectorNames()

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

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

### 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.

### getClassPath

    public String getClassPath()

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

  Returns:
    Returns the classLoader.

### getContextPath

    public String getContextPath()

  Returns:
    Returns the _contextPath.

### getInitParameter

    public String getInitParameter(String name)

### getInitParameterNames

    public Enumeration getInitParameterNames()

### getInitParams

    public Map getInitParams()

  Returns:
    Returns the initParams.

### getDisplayName

    public String getDisplayName()

### getEventListeners

    public EventListener[] getEventListeners()

### setEventListeners

    public void setEventListeners(EventListener[] eventListeners)

### addEventListener

    public void addEventListener(EventListener 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:
    `accepting` - true if this context is accepting new requests

### doStart

    protected void doStart()
                    throws Exception

  Overrides:
    `doStart` in class `HandlerWrapper`
  Throws:
    `Exception`

### startContext

    protected void startContext()
                         throws Exception

  Throws:
    `Exception`

### doStop

    protected void doStop()
                   throws Exception

  Overrides:
    `doStop` in class `HandlerWrapper`
  Throws:
    `Exception`

### handle

    public void handle(String target,
                       HttpServletRequest request,
                       HttpServletResponse response,
                       int dispatch)
                throws IOException,
                       ServletException

  Description copied from interface: `Handler`
  Handle a request.

  Specified by:
    `handle` in interface `Handler`
  Overrides:
    `handle` in class `HandlerWrapper`
  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`
  Throws:
    `IOException`
    `ServletException`

### isProtectedTarget

    protected boolean isProtectedTarget(String target)

  Check the target. Called by `handle(String, HttpServletRequest, HttpServletResponse, int)` when a target within a context is determined. If the target is protected, 404 is returned. The default implementation always returns false.

  See Also:
    `WebAppContext.isProtectedTarget(String)`

### 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(Map 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:
    `base` - 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:
    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 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)

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-2008 Mort Bay Consulting. All Rights Reserved.