org.eclipse.jetty.servlet

## Class ServletHandler

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

- All Implemented Interfaces:
    Handler, HandlerContainer, Destroyable, Dumpable, LifeCycle
  Direct Known Subclasses:
    ServletHandler

      public class ServletHandler
      extends ScopedHandler

  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 directly when a full web application is not required. If a Web application is required, then this handler should be used as part of a `org.eclipse.jetty.webapp.WebAppContext`.

  Unless run as part of a `ServletContextHandler` or derivative, the `initialize()` method must be called manually after start().

- - ### Nested Class Summary

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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `__DEFAULT_SERVLET`
    `protected ConcurrentMap<String,javax.servlet.FilterChain>[]` | `_chainCache`
    `protected Queue<String>[]` | `_chainLRU`

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

    Constructors
    Constructor and Description
    `ServletHandler()` Constructor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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(String className, String pathSpec, EnumSet<DispatcherType> dispatches)` Deprecated. use `addFilterWithMapping(Class, String, int)` instead
    `void` | `addFilterMapping(FilterMapping mapping)` Convenience method to add a preconstructed FilterMapping
    `FilterHolder` | `addFilterWithMapping(Class<? extends javax.servlet.Filter> filter, String pathSpec, EnumSet<DispatcherType> dispatches)` Convenience method to add a filter.
    `FilterHolder` | `addFilterWithMapping(Class<? extends javax.servlet.Filter> filter, String pathSpec, int dispatches)` Convenience method to add a filter.
    `void` | `addFilterWithMapping(FilterHolder holder, String pathSpec, EnumSet<DispatcherType> dispatches)` Convenience method to add a filter.
    `void` | `addFilterWithMapping(FilterHolder holder, String pathSpec, int dispatches)` Convenience method to add a filter.
    `FilterHolder` | `addFilterWithMapping(String className, String pathSpec, EnumSet<DispatcherType> dispatches)` Convenience method to add a filter.
    `FilterHolder` | `addFilterWithMapping(String className, String pathSpec, int dispatches)` Convenience method to add a filter.
    `void` | `addServlet(ServletHolder holder)` Convenience method to add a pre-constructed ServletHolder.
    `void` | `addServletMapping(ServletMapping mapping)` Convenience method to add a pre-constructed ServletMapping.
    `ServletHolder` | `addServletWithMapping(Class<? extends javax.servlet.Servlet> servlet, String pathSpec)` conveniance method to add a servlet.
    `void` | `addServletWithMapping(ServletHolder servlet, String pathSpec)` conveniance method to add a servlet.
    `ServletHolder` | `addServletWithMapping(String className, String pathSpec)` Convenience method to add a servlet.
    `void` | `doHandle(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
    `void` | `doScope(String target, Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.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)`
    `Object` | `getContextLog()`
    `FilterHolder` | `getFilter(String name)`
    `FilterMapping[]` | `getFilterMappings()`
    `FilterHolder[]` | `getFilters()` Get Filters.
    `PathMap.Entry` | `getHolderEntry(String pathInContext)` ServletHolder matching path.
    `int` | `getMaxFilterChainsCacheSize()`
    `ServletHolder` | `getServlet(String name)`
    `javax.servlet.ServletContext` | `getServletContext()`
    `ServletMapping` | `getServletMapping(String pattern)`
    `ServletMapping[]` | `getServletMappings()`
    `ServletHolder[]` | `getServlets()` Get Servlets.
    `void` | `initialize()` Initialize filters and load-on-startup servlets.
    `boolean` | `isAvailable()`
    `boolean` | `isFilterChainsCached()`
    `boolean` | `isStartWithUnavailable()`
    `FilterHolder` | `newFilterHolder()`
    `FilterHolder` | `newFilterHolder(Class<? extends javax.servlet.Filter> filter)`
    `ServletHolder` | `newServletHolder()` see also newServletHolder(Class)
    `ServletHolder` | `newServletHolder(Class<? extends javax.servlet.Servlet> servlet)`
    `protected void` | `notFound(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)`
    `void` | `prependFilterMapping(FilterMapping mapping)` Convenience method to add a preconstructed FilterMapping
    `void` | `setFilterChainsCached(boolean filterChainsCached)`
    `void` | `setFilterMappings(FilterMapping[] filterMappings)`
    `void` | `setFilters(FilterHolder[] holders)`
    `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.eclipse.jetty.server.handler.ScopedHandler

      `handle, never, nextHandle, nextScope`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.HandlerWrapper

      `destroy, expandChildren, getHandler, getHandlers, getNestedHandlerByClass, setHandler`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandlerContainer

      `expandHandler, findContainerOf, getChildHandlerByClass, getChildHandlers, getChildHandlersByClass`

    - ### Methods inherited from class org.eclipse.jetty.server.handler.AbstractHandler

      `dumpThis, getServer`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AggregateLifeCycle

      `addBean, addBean, contains, dump, dump, dump, dump, dumpObject, dumpStdErr, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, unmanage`

    - ### Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

      `addLifeCycleListener, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.util.component.LifeCycle

      `addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

- - ### Field Detail

    - #### __DEFAULT_SERVLET

          public static final String __DEFAULT_SERVLET

      See Also:
        Constant Field Values

    - #### _chainCache

          protected final ConcurrentMap<String,javax.servlet.FilterChain>[] _chainCache

    - #### _chainLRU

          protected final Queue<String>[] _chainLRU

  - ### Constructor Detail

    - #### ServletHandler

          public ServletHandler()

      Constructor.

  - ### Method Detail

    - #### setServer

          public void setServer(Server server)

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

    - #### doStart

          protected void doStart()
                          throws Exception

      Description copied from class: `AggregateLifeCycle`
      Start the managed lifecycle beans in the order they were added.
      Overrides:
        `doStart` in class `ScopedHandler`
      Throws:
        `Exception`
      See Also:
        `HandlerWrapper.doStart()`

    - #### doStop

          protected void doStop()
                         throws Exception

      Description copied from class: `AggregateLifeCycle`
      Stop the joined lifecycle beans in the reverse order they were added.
      Overrides:
        `doStop` in class `HandlerWrapper`
      Throws:
        `Exception`
      See Also:
        `AbstractLifeCycle.doStart()`

    - #### getContextLog

          public 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(String pathInContext)

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

    - #### getServletContext

          public javax.servlet.ServletContext getServletContext()

    - #### getServletMappings

          public ServletMapping[] getServletMappings()

      Returns:
        Returns the servletMappings.

    - #### getServletMapping

          public ServletMapping getServletMapping(String pattern)

      Returns:
        Returns the servletMappings.

    - #### getServlets

          public ServletHolder[] getServlets()

      Get Servlets.
      Returns:
        Array of defined servlets

    - #### getServlet

          public ServletHolder getServlet(String name)

    - #### doScope

          public void doScope(String target,
                     Request baseRequest,
                     javax.servlet.http.HttpServletRequest request,
                     javax.servlet.http.HttpServletResponse response)
                       throws IOException,
                              javax.servlet.ServletException

      Specified by:
        `doScope` in class `ScopedHandler`
      Throws:
        `IOException`
        `javax.servlet.ServletException`

    - #### doHandle

          public void doHandle(String target,
                      Request baseRequest,
                      javax.servlet.http.HttpServletRequest request,
                      javax.servlet.http.HttpServletResponse response)
                        throws IOException,
                               javax.servlet.ServletException

      Specified by:
        `doHandle` in class `ScopedHandler`
      Throws:
        `IOException`
        `javax.servlet.ServletException`

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

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

    - #### isFilterChainsCached

          public boolean isFilterChainsCached()

      Returns:
        Returns the filterChainsCached.

    - #### newServletHolder

          public ServletHolder newServletHolder()

      see also newServletHolder(Class)

    - #### newServletHolder

          public ServletHolder newServletHolder(Class<? extends javax.servlet.Servlet> servlet)

    - #### addServletWithMapping

          public ServletHolder addServletWithMapping(String className,
                                            String pathSpec)

      Convenience method to add a servlet.
      Returns:
        The servlet holder.

    - #### addServletWithMapping

          public ServletHolder addServletWithMapping(Class<? extends javax.servlet.Servlet> servlet,
                                            String pathSpec)

      conveniance method to add a servlet.
      Returns:
        The servlet holder.

    - #### addServletWithMapping

          public void addServletWithMapping(ServletHolder servlet,
                                   String pathSpec)

      conveniance method to add a servlet.
      Parameters:
        `servlet` - servlet holder to add
        `pathSpec` - servlet mappings for the servletHolder

    - #### 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(Class<? extends javax.servlet.Filter> filter)

    - #### newFilterHolder

          public FilterHolder newFilterHolder()

      See Also:
        `newFilterHolder(Class)`

    - #### getFilter

          public FilterHolder getFilter(String name)

    - #### addFilterWithMapping

          public FilterHolder addFilterWithMapping(Class<? extends javax.servlet.Filter> filter,
                                          String pathSpec,
                                          EnumSet<DispatcherType> dispatches)

      Convenience method to add a filter.
      Parameters:
        `filter` - class of filter to create
        `pathSpec` - filter mappings for filter
        `dispatches` - see `FilterMapping.setDispatches(int)`
      Returns:
        The filter holder.

    - #### addFilterWithMapping

          public FilterHolder addFilterWithMapping(String className,
                                          String pathSpec,
                                          EnumSet<DispatcherType> dispatches)

      Convenience method to add a filter.
      Parameters:
        `className` - of filter
        `pathSpec` - filter mappings for filter
        `dispatches` - see `FilterMapping.setDispatches(int)`
      Returns:
        The filter holder.

    - #### addFilterWithMapping

          public void addFilterWithMapping(FilterHolder holder,
                                  String pathSpec,
                                  EnumSet<DispatcherType> dispatches)

      Convenience method to add a filter.
      Parameters:
        `holder` - filter holder to add
        `pathSpec` - filter mappings for filter
        `dispatches` - see `FilterMapping.setDispatches(int)`

    - #### addFilterWithMapping

          public FilterHolder addFilterWithMapping(Class<? extends javax.servlet.Filter> filter,
                                          String pathSpec,
                                          int dispatches)

      Convenience method to add a filter.
      Parameters:
        `filter` - class of filter to create
        `pathSpec` - filter mappings for filter
        `dispatches` - see `FilterMapping.setDispatches(int)`
      Returns:
        The filter holder.

    - #### addFilterWithMapping

          public FilterHolder addFilterWithMapping(String className,
                                          String pathSpec,
                                          int dispatches)

      Convenience method to add a filter.
      Parameters:
        `className` - of filter
        `pathSpec` - filter mappings for filter
        `dispatches` - see `FilterMapping.setDispatches(int)`
      Returns:
        The filter holder.

    - #### addFilterWithMapping

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

      Convenience method to add a filter.
      Parameters:
        `holder` - filter holder to add
        `pathSpec` - filter mappings for filter
        `dispatches` - see `FilterMapping.setDispatches(int)`

    - #### addFilter

          public FilterHolder addFilter(String className,
                               String pathSpec,
                               EnumSet<DispatcherType> dispatches)

      Deprecated. use `addFilterWithMapping(Class, String, int)` instead
      Convenience method to add a filter with a mapping
      Parameters:
        `className` -
        `pathSpec` -
        `dispatches` -
      Returns:
        the filter holder created

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

    - #### prependFilterMapping

          public void prependFilterMapping(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 IOException

      Throws:
        `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.

    - #### dump

          public void dump(Appendable out,
                  String indent)
                    throws IOException

      Specified by:
        `dump` in interface `Dumpable`
      Overrides:
        `dump` in class `AbstractHandlerContainer`
      Throws:
        `IOException`

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