org.eclipse.jetty.servlet

## Class ServletHolder

- java.lang.Object
- - org.eclipse.jetty.util.component.AbstractLifeCycle
  - - org.eclipse.jetty.servlet.Holder<javax.servlet.Servlet>
    - - org.eclipse.jetty.servlet.ServletHolder

- All Implemented Interfaces:
    Comparable, UserIdentity.Scope, Dumpable, LifeCycle

      public class ServletHolder
      extends Holder<javax.servlet.Servlet>
      implements UserIdentity.Scope, Comparable

  Servlet Instance and Context Holder. Holds the name, params and some state of a javax.servlet.Servlet instance. It implements the ServletConfig interface. This class will organise the loading of the servlet when needed or requested.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected class` | `ServletHolder.Config`
    `class` | `ServletHolder.Registration`

    - ### Nested classes/interfaces inherited from class org.eclipse.jetty.servlet.Holder

      `Holder.HolderConfig, Holder.HolderRegistration, Holder.Source`

    - ### 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 Map<String,String>` | `NO_MAPPED_ROLES`

    - ### Fields inherited from class org.eclipse.jetty.servlet.Holder

      `_asyncSupported, _class, _className, _displayName, _extInstance, _initParams, _name, _servletHandler`

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

      `_listeners, FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ServletHolder()` Constructor .
    `ServletHolder(Class<? extends javax.servlet.Servlet> servlet)` Constructor for servlet class.
    `ServletHolder(Holder.Source creator)` Constructor .
    `ServletHolder(javax.servlet.Servlet servlet)` Constructor for existing servlet.
    `ServletHolder(String name, Class<? extends javax.servlet.Servlet> servlet)` Constructor for servlet class.
    `ServletHolder(String name, javax.servlet.Servlet servlet)` Constructor for servlet class.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `checkServletType()` Check to ensure class of servlet is acceptable.
    `int` | `compareTo(Object o)` Comparitor by init order.
    `void` | `destroyInstance(Object o)`
    `void` | `doStart()`
    `void` | `doStop()`
    `boolean` | `equals(Object o)`
    `String` | `getContextPath()`
    `String` | `getForcedPath()`
    `int` | `getInitOrder()`
    `javax.servlet.ServletRegistration.Dynamic` | `getRegistration()`
    `Map<String,String>` | `getRoleMap()`
    `Map<String,String>` | `getRoleRefMap()`
    `String` | `getRunAsRole()`
    `javax.servlet.Servlet` | `getServlet()` Get the servlet.
    `javax.servlet.Servlet` | `getServletInstance()` Get the servlet instance (no initialization done).
    `javax.servlet.UnavailableException` | `getUnavailableException()`
    `String` | `getUserRoleLink(String name)` get a user role link.
    `void` | `handle(Request baseRequest, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)` Service a request with this servlet.
    `int` | `hashCode()`
    `protected void` | `initJspServlet()`
    `protected void` | `initMultiPart()` Register a ServletRequestListener that will ensure tmp multipart files are deleted when the request goes out of scope.
    `boolean` | `isAvailable()`
    `boolean` | `isEnabled()`
    `boolean` | `isSetInitOrder()`
    `protected javax.servlet.Servlet` | `newInstance()`
    `void` | `setEnabled(boolean enabled)`
    `void` | `setForcedPath(String forcedPath)`
    `void` | `setInitOrder(int order)` Set the initialize order.
    `void` | `setRunAsRole(String role)`
    `void` | `setServlet(javax.servlet.Servlet servlet)`
    `void` | `setUserRoleLink(String name, String link)` Link a user role.

    - ### Methods inherited from class org.eclipse.jetty.servlet.Holder

      `dump, dump, getClassName, getDisplayName, getHeldClass, getInitParameter, getInitParameterNames, getInitParameters, getName, getServletHandler, getSource, illegalStateIfContextStarted, isAsyncSupported, isInstance, setAsyncSupported, setClassName, setDisplayName, setHeldClass, setInitParameter, setInitParameters, setName, setServletHandler, toString`

    - ### 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, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.eclipse.jetty.server.UserIdentity.Scope

      `getName`

- - ### Field Detail

    - #### NO_MAPPED_ROLES

          public static final Map<String,String> NO_MAPPED_ROLES

  - ### Constructor Detail

    - #### ServletHolder

          public ServletHolder()

      Constructor .

    - #### ServletHolder

          public ServletHolder(Holder.Source creator)

      Constructor .

    - #### ServletHolder

          public ServletHolder(javax.servlet.Servlet servlet)

      Constructor for existing servlet.

    - #### ServletHolder

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

      Constructor for servlet class.

    - #### ServletHolder

          public ServletHolder(String name,
                       javax.servlet.Servlet servlet)

      Constructor for servlet class.

    - #### ServletHolder

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

      Constructor for servlet class.

  - ### Method Detail

    - #### getUnavailableException

          public javax.servlet.UnavailableException getUnavailableException()

      Returns:
        The unavailable exception or null if not unavailable

    - #### setServlet

          public void setServlet(javax.servlet.Servlet servlet)

    - #### getInitOrder

          public int getInitOrder()

    - #### setInitOrder

          public void setInitOrder(int order)

      Set the initialize order. Holders with order<0, are initialized on use. Those with order>=0 are initialized in increasing order when the handler is started.

    - #### isSetInitOrder

          public boolean isSetInitOrder()

    - #### compareTo

          public int compareTo(Object o)

      Comparitor by init order.
      Specified by:
        `compareTo` in interface `Comparable`

    - #### equals

          public boolean equals(Object o)

      Overrides:
        `equals` in class `Object`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### setUserRoleLink

          public void setUserRoleLink(String name,
                             String link)

      Link a user role. Translate the role name used by a servlet, to the link name used by the container.
      Parameters:
        `name` - The role name as used by the servlet
        `link` - The role name as used by the container.

    - #### getUserRoleLink

          public String getUserRoleLink(String name)

      get a user role link.
      Parameters:
        `name` - The name of the role
      Returns:
        The name as translated by the link. If no link exists, the name is returned.

    - #### getRoleMap

          public Map<String,String> getRoleMap()

    - #### getForcedPath

          public String getForcedPath()

      Returns:
        Returns the forcedPath.

    - #### setForcedPath

          public void setForcedPath(String forcedPath)

      Parameters:
        `forcedPath` - The forcedPath to set.

    - #### isEnabled

          public boolean isEnabled()

    - #### setEnabled

          public void setEnabled(boolean enabled)

    - #### doStart

          public void doStart()
                       throws Exception

      Overrides:
        `doStart` in class `Holder<javax.servlet.Servlet>`
      Throws:
        `Exception`

    - #### doStop

          public void doStop()
                      throws Exception

      Overrides:
        `doStop` in class `Holder<javax.servlet.Servlet>`
      Throws:
        `Exception`

    - #### destroyInstance

          public void destroyInstance(Object o)
                               throws Exception

      Overrides:
        `destroyInstance` in class `Holder<javax.servlet.Servlet>`
      Throws:
        `Exception`

    - #### getServlet

          public javax.servlet.Servlet getServlet()
                                           throws javax.servlet.ServletException

      Get the servlet.
      Returns:
        The servlet
      Throws:
        `javax.servlet.ServletException`

    - #### getServletInstance

          public javax.servlet.Servlet getServletInstance()

      Get the servlet instance (no initialization done).
      Returns:
        The servlet or null

    - #### checkServletType

          public void checkServletType()
                                throws javax.servlet.UnavailableException

      Check to ensure class of servlet is acceptable.
      Throws:
        `javax.servlet.UnavailableException`

    - #### isAvailable

          public boolean isAvailable()

      Returns:
        true if the holder is started and is not unavailable

    - #### initJspServlet

          protected void initJspServlet()
                                 throws Exception

      Throws:
        `Exception`

    - #### initMultiPart

          protected void initMultiPart()
                                throws Exception

      Register a ServletRequestListener that will ensure tmp multipart files are deleted when the request goes out of scope.
      Throws:
        `Exception`

    - #### getContextPath

          public String getContextPath()

      Specified by:
        `getContextPath` in interface `UserIdentity.Scope`
      Returns:
        The context path that the identity is being considered within
      See Also:
        `UserIdentity.Scope.getContextPath()`

    - #### getRoleRefMap

          public Map<String,String> getRoleRefMap()

      Specified by:
        `getRoleRefMap` in interface `UserIdentity.Scope`
      Returns:
        A map of role reference names that converts from names used by application code to names used by the context deployment.
      See Also:
        `UserIdentity.Scope.getRoleRefMap()`

    - #### getRunAsRole

          public String getRunAsRole()

    - #### setRunAsRole

          public void setRunAsRole(String role)

    - #### handle

          public void handle(Request baseRequest,
                    javax.servlet.ServletRequest request,
                    javax.servlet.ServletResponse response)
                      throws javax.servlet.ServletException,
                             javax.servlet.UnavailableException,
                             IOException

      Service a request with this servlet.
      Throws:
        `javax.servlet.ServletException`
        `javax.servlet.UnavailableException`
        `IOException`

    - #### getRegistration

          public javax.servlet.ServletRegistration.Dynamic getRegistration()

    - #### newInstance

          protected javax.servlet.Servlet newInstance()
                                               throws javax.servlet.ServletException,
                                                      IllegalAccessException,
                                                      InstantiationException

      Returns:
        the newly created Servlet instance
      Throws:
        `javax.servlet.ServletException`
        `IllegalAccessException`
        `InstantiationException`

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