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.servlet
Class ServletHandler

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.handler.AbstractHandler
              org.mortbay.jetty.servlet.ServletHandler

All Implemented Interfaces:
  LifeCycle, Handler

Direct Known Subclasses:
  ServletHandler

    public class ServletHandler

extends AbstractHandler

Servlet HttpHandler. This handler maps requests to servlets that implement the javax.servlet.http.HttpServlet API.

This handler does not implement the full J2EE features and is intended to be used when a full web application is not required. Specifically filters and request wrapping are not supported. Unless run as part of a `Context` or derivative, the `initialize()` method must be called manually after start().

Author:
  Greg Wilkins
See Also:
  `WebAppContext`

Nested Class Summary

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

Field Summary
`static java.lang.String` | `__DEFAULT_SERVLET`
`static java.lang.String` | `__J_S_CONTEXT_TEMPDIR`
`static java.lang.String` | `__J_S_ERROR_EXCEPTION`
`static java.lang.String` | `__J_S_ERROR_EXCEPTION_TYPE`
`static java.lang.String` | `__J_S_ERROR_MESSAGE`
`static java.lang.String` | `__J_S_ERROR_REQUEST_URI`
`static java.lang.String` | `__J_S_ERROR_SERVLET_NAME`
`static java.lang.String` | `__J_S_ERROR_STATUS_CODE`
`protected org.mortbay.jetty.servlet.ServletHandler.MruCache[]` | `_chainCache`

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
`ServletHandler()` Constructor.

Method Summary
`void` | `addFilter(FilterHolder filter)` Convenience method to add a preconstructed FilterHolder
`void` | `addFilter(FilterHolder filter, FilterMapping filterMapping)` convenience method to add a filter and mapping
`FilterHolder` | `addFilter(java.lang.String className, java.lang.String pathSpec, int dispatches)` Deprecated.
`void` | `addFilterMapping(FilterMapping mapping)` Convenience method to add a preconstructed FilterMapping
`FilterHolder` | `addFilterWithMapping(java.lang.Class filter, java.lang.String pathSpec, int dispatches)` conveniance method to add a filter.
`void` | `addFilterWithMapping(FilterHolder holder, java.lang.String pathSpec, int dispatches)` conveniance method to add a filter.
`FilterHolder` | `addFilterWithMapping(java.lang.String className, java.lang.String pathSpec, int dispatches)` conveniance method to add a filter.
`void` | `addServlet(ServletHolder holder)` Convenience method to add a pre-constructed ServletHolder.
`ServletHolder` | `addServlet(java.lang.String className, java.lang.String pathSpec)` Deprecated.
`void` | `addServletMapping(ServletMapping mapping)` Convenience method to add a pre-constructed ServletMapping.
`ServletHolder` | `addServletWithMapping(java.lang.Class servlet, java.lang.String pathSpec)` conveniance method to add a servlet.
`void` | `addServletWithMapping(ServletHolder servlet, java.lang.String pathSpec)` conveniance method to add a servlet.
`ServletHolder` | `addServletWithMapping(java.lang.String className, java.lang.String pathSpec)` conveniance method to add a servlet.
`javax.servlet.Filter` | `customizeFilter(javax.servlet.Filter filter)` Customize a Filter.
`javax.servlet.Filter` | `customizeFilterDestroy(javax.servlet.Filter filter)`
`javax.servlet.Servlet` | `customizeServlet(javax.servlet.Servlet servlet)` Customize a servlet.
`javax.servlet.Servlet` | `customizeServletDestroy(javax.servlet.Servlet servlet)`
`protected void` | `doStart()`
`protected void` | `doStop()`
`java.lang.Object` | `getContextLog()`
`FilterHolder` | `getFilter(java.lang.String name)`
`FilterMapping[]` | `getFilterMappings()`
`FilterHolder[]` | `getFilters()` Get Filters.
`PathMap.Entry` | `getHolderEntry(java.lang.String pathInContext)` ServletHolder matching path.
`int` | `getMaxFilterChainsCacheSize()`
`javax.servlet.RequestDispatcher` | `getRequestDispatcher(java.lang.String uriInContext)`
`ServletHolder` | `getServlet(java.lang.String name)`
`javax.servlet.ServletContext` | `getServletContext()`
`ServletMapping[]` | `getServletMappings()`
`ServletHolder[]` | `getServlets()` Get Servlets.
`void` | `handle(java.lang.String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, int type)` Handle a request.
`void` | `initialize()` Initialize filters and load-on-startup servlets.
`boolean` | `isAvailable()`
`boolean` | `isFilterChainsCached()`
`boolean` | `isInitializeAtStart()` Deprecated.
`boolean` | `isStartWithUnavailable()`
`boolean` | `matchesPath(java.lang.String pathInContext)` Whether there is a ServletHolder that matches this path
`FilterHolder` | `newFilterHolder()`
`FilterHolder` | `newFilterHolder(java.lang.Class filter)`
`ServletHolder` | `newServletHolder()`
`ServletHolder` | `newServletHolder(java.lang.Class servlet)`
`protected void` | `notFound(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
`void` | `setFilterChainsCached(boolean filterChainsCached)`
`void` | `setFilterMappings(FilterMapping[] filterMappings)`
`void` | `setFilters(FilterHolder[] holders)`
`void` | `setInitializeAtStart(boolean initializeAtStart)` Deprecated.
`void` | `setMaxFilterChainsCacheSize(int maxFilterChainsCacheSize)` Set the maximum filter chain cache size.
`void` | `setServer(Server server)`
`void` | `setServletMappings(ServletMapping[] servletMappings)`
`void` | `setServlets(ServletHolder[] holders)` Set Servlets.
`void` | `setStartWithUnavailable(boolean start)`
`protected void` | `updateMappings()`
`protected void` | `updateNameMappings()`

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

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

### __DEFAULT_SERVLET

    public static final java.lang.String __DEFAULT_SERVLET

See Also:
  Constant Field Values

### __J_S_CONTEXT_TEMPDIR

    public static final java.lang.String __J_S_CONTEXT_TEMPDIR

See Also:
  Constant Field Values

### __J_S_ERROR_EXCEPTION

    public static final java.lang.String __J_S_ERROR_EXCEPTION

See Also:
  Constant Field Values

### __J_S_ERROR_EXCEPTION_TYPE

    public static final java.lang.String __J_S_ERROR_EXCEPTION_TYPE

See Also:
  Constant Field Values

### __J_S_ERROR_MESSAGE

    public static final java.lang.String __J_S_ERROR_MESSAGE

See Also:
  Constant Field Values

### __J_S_ERROR_REQUEST_URI

    public static final java.lang.String __J_S_ERROR_REQUEST_URI

See Also:
  Constant Field Values

### __J_S_ERROR_SERVLET_NAME

    public static final java.lang.String __J_S_ERROR_SERVLET_NAME

See Also:
  Constant Field Values

### __J_S_ERROR_STATUS_CODE

    public static final java.lang.String __J_S_ERROR_STATUS_CODE

See Also:
  Constant Field Values

### _chainCache

    protected transient org.mortbay.jetty.servlet.ServletHandler.MruCache[] _chainCache

Constructor Detail

### ServletHandler

    public ServletHandler()

  Constructor.

Method Detail

### setServer

    public void setServer(Server server)

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

### doStart

    protected void doStart()
                    throws java.lang.Exception

  Overrides:
    `doStart` in class `AbstractHandler`
  Throws:
    `java.lang.Exception`

### doStop

    protected void doStop()
                   throws java.lang.Exception

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

### getContextLog

    public java.lang.Object getContextLog()

  Returns:
    Returns the contextLog.

### getFilterMappings

    public FilterMapping[] getFilterMappings()

  Returns:
    Returns the filterMappings.

### getFilters

    public FilterHolder[] getFilters()

  Get Filters.

  Returns:
    Array of defined servlets

### getHolderEntry

    public PathMap.Entry getHolderEntry(java.lang.String pathInContext)

  ServletHolder matching path.

  Parameters:
    `pathInContext` - Path within _context.
  Returns:
    PathMap Entries pathspec to ServletHolder

### matchesPath

    public boolean matchesPath(java.lang.String pathInContext)

  Whether there is a ServletHolder that matches this path

  Parameters:
    `pathInContext` - Path within _context.
  Returns:
    whether there is a ServletHolder that matches this path

### getRequestDispatcher

    public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String uriInContext)

  Returns:
    A `dispatcher` wrapping the resource at `uriInContext`, or `null` if the specified uri cannot be dispatched to.

### getServletContext

    public javax.servlet.ServletContext getServletContext()

### getServletMappings

    public ServletMapping[] getServletMappings()

  Returns:
    Returns the servletMappings.

### getServlets

    public ServletHolder[] getServlets()

  Get Servlets.

  Returns:
    Array of defined servlets

### getServlet

    public ServletHolder getServlet(java.lang.String name)

### handle

    public void handle(java.lang.String target,
                       javax.servlet.http.HttpServletRequest request,
                       javax.servlet.http.HttpServletResponse response,
                       int type)
                throws java.io.IOException,
                       javax.servlet.ServletException

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

  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.
    `type` - The dispatch mode: `Handler.REQUEST`, `Handler.FORWARD`, `Handler.INCLUDE`, `Handler.ERROR`
  Throws:
    `java.io.IOException`
    `javax.servlet.ServletException`

### isInitializeAtStart

    public boolean isInitializeAtStart()

  Deprecated.

  Returns:
    Returns the initializeAtStart.

### setInitializeAtStart

    public void setInitializeAtStart(boolean initializeAtStart)

  Deprecated.

  Parameters:
    `initializeAtStart` - The initializeAtStart to set.

### isAvailable

    public boolean isAvailable()

  Returns:
    true if the handler is started and there are no unavailable servlets

### setStartWithUnavailable

    public void setStartWithUnavailable(boolean start)

  Parameters:
    `start` - True if this handler will start with unavailable servlets

### isStartWithUnavailable

    public boolean isStartWithUnavailable()

  Returns:
    True if this handler will start with unavailable servlets

### initialize

    public void initialize()
                    throws java.lang.Exception

  Initialize filters and load-on-startup servlets. Called automatically from start if autoInitializeServlet is true.

  Throws:
    `java.lang.Exception`

### isFilterChainsCached

    public boolean isFilterChainsCached()

  Returns:
    Returns the filterChainsCached.

### newServletHolder

    public ServletHolder newServletHolder()

  See Also:
    `newServletHolder(Class)`

### newServletHolder

    public ServletHolder newServletHolder(java.lang.Class servlet)

### addServletWithMapping

    public ServletHolder addServletWithMapping(java.lang.String className,
                                               java.lang.String pathSpec)

  conveniance method to add a servlet.

  Returns:
    The servlet holder.

### addServletWithMapping

    public ServletHolder addServletWithMapping(java.lang.Class servlet,
                                               java.lang.String pathSpec)

  conveniance method to add a servlet.

  Returns:
    The servlet holder.

### addServletWithMapping

    public void addServletWithMapping(ServletHolder servlet,
                                      java.lang.String pathSpec)

  conveniance method to add a servlet.

  Parameters:
    `name` -
    `className` -
    `pathSpec` -

### addServlet

    public ServletHolder addServlet(java.lang.String className,
                                    java.lang.String pathSpec)

  Deprecated.

  Convenience method to add a servlet with a servlet mapping.

  Parameters:
    `className` -
    `pathSpec` -
  Returns:

### addServlet

    public void addServlet(ServletHolder holder)

  Convenience method to add a pre-constructed ServletHolder.

  Parameters:
    `holder` -

### addServletMapping

    public void addServletMapping(ServletMapping mapping)

  Convenience method to add a pre-constructed ServletMapping.

  Parameters:
    `mapping` -

### newFilterHolder

    public FilterHolder newFilterHolder(java.lang.Class filter)

### newFilterHolder

    public FilterHolder newFilterHolder()

  See Also:
    `#newFilterHolder(Class)}`

### getFilter

    public FilterHolder getFilter(java.lang.String name)

### addFilterWithMapping

    public FilterHolder addFilterWithMapping(java.lang.Class filter,
                                             java.lang.String pathSpec,
                                             int dispatches)

  conveniance method to add a filter.

  Parameters:
    `name` -
    `className` -
    `pathSpec` -
    `dispatches` - see `FilterMapping.setDispatches(int)`
  Returns:
    The filter holder.

### addFilterWithMapping

    public FilterHolder addFilterWithMapping(java.lang.String className,
                                             java.lang.String pathSpec,
                                             int dispatches)

  conveniance method to add a filter.

  Parameters:
    `name` -
    `className` -
    `pathSpec` -
    `dispatches` - see `FilterMapping.setDispatches(int)`
  Returns:
    The filter holder.

### addFilterWithMapping

    public void addFilterWithMapping(FilterHolder holder,
                                     java.lang.String pathSpec,
                                     int dispatches)

  conveniance method to add a filter.

  Parameters:
    `name` -
    `className` -
    `pathSpec` -
    `dispatches` - see `FilterMapping.setDispatches(int)`

### addFilter

    public FilterHolder addFilter(java.lang.String className,
                                  java.lang.String pathSpec,
                                  int dispatches)

  Deprecated.

  Convenience method to add a filter with a mapping

  Parameters:
    `className` -
    `pathSpec` -
    `dispatches` -
  Returns:

### addFilter

    public void addFilter(FilterHolder filter,
                          FilterMapping filterMapping)

  convenience method to add a filter and mapping

  Parameters:
    `filter` -
    `filterMapping` -

### addFilter

    public void addFilter(FilterHolder filter)

  Convenience method to add a preconstructed FilterHolder

  Parameters:
    `filter` -

### addFilterMapping

    public void addFilterMapping(FilterMapping mapping)

  Convenience method to add a preconstructed FilterMapping

  Parameters:
    `mapping` -

### updateNameMappings

    protected void updateNameMappings()

### updateMappings

    protected void updateMappings()

### notFound

    protected void notFound(javax.servlet.http.HttpServletRequest request,
                            javax.servlet.http.HttpServletResponse response)
                     throws java.io.IOException

  Throws:
    `java.io.IOException`

### setFilterChainsCached

    public void setFilterChainsCached(boolean filterChainsCached)

  Parameters:
    `filterChainsCached` - The filterChainsCached to set.

### setFilterMappings

    public void setFilterMappings(FilterMapping[] filterMappings)

  Parameters:
    `filterMappings` - The filterMappings to set.

### setFilters

    public void setFilters(FilterHolder[] holders)

### setServletMappings

    public void setServletMappings(ServletMapping[] servletMappings)

  Parameters:
    `servletMappings` - The servletMappings to set.

### setServlets

    public void setServlets(ServletHolder[] holders)

  Set Servlets.

  Parameters:
    `holders` - Array of servletsto define

### getMaxFilterChainsCacheSize

    public int getMaxFilterChainsCacheSize()

  Returns:
    The maximum entries in a filter chain cache.

### setMaxFilterChainsCacheSize

    public void setMaxFilterChainsCacheSize(int maxFilterChainsCacheSize)

  Set the maximum filter chain cache size. Filter chains are cached if `isFilterChainsCached()` is true. If the max cache size is greater than zero, then the cache is flushed whenever it grows to be this size.

  Parameters:
    `maxFilterChainsCacheSize` - the maximum number of entries in a filter chain cache.

### customizeServlet

    public javax.servlet.Servlet customizeServlet(javax.servlet.Servlet servlet)
                                           throws java.lang.Exception

  Customize a servlet. Called before the servlet goes into service. Subclasses of ServletHandler should override this method.

  Parameters:
    `servlet` -
  Returns:
  Throws:
    `java.lang.Exception`

### customizeServletDestroy

    public javax.servlet.Servlet customizeServletDestroy(javax.servlet.Servlet servlet)
                                                  throws java.lang.Exception

  Throws:
    `java.lang.Exception`

### customizeFilter

    public javax.servlet.Filter customizeFilter(javax.servlet.Filter filter)
                                         throws java.lang.Exception

  Customize a Filter. Called before the Filter goes into service. Subclasses of ServletHandler should override this method.

  Parameters:
    `filter` -
  Returns:
  Throws:
    `java.lang.Exception`

### customizeFilterDestroy

    public javax.servlet.Filter customizeFilterDestroy(javax.servlet.Filter filter)
                                                throws java.lang.Exception

  Throws:
    `java.lang.Exception`

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.