Class ServletHolder

All Implemented Interfaces:
Comparable<ServletHolder>, Dumpable, LifeCycle

@ManagedObject("Servlet Holder") public class ServletHolder extends Holder<jakarta.servlet.Servlet> implements Comparable<ServletHolder>
Servlet Instance and Context Holder.

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

  • Field Details

  • Constructor Details

    • ServletHolder

      public ServletHolder()
      Constructor .
    • ServletHolder

      public ServletHolder(Source creator)
      Constructor .
      Parameters:
      creator - the holder source
    • ServletHolder

      public ServletHolder(jakarta.servlet.Servlet servlet)
      Constructor for existing servlet.
      Parameters:
      servlet - the servlet
    • ServletHolder

      public ServletHolder(String name, Class<? extends jakarta.servlet.Servlet> servlet)
      Constructor for servlet class.
      Parameters:
      name - the name of the servlet
      servlet - the servlet class
    • ServletHolder

      public ServletHolder(String name, jakarta.servlet.Servlet servlet)
      Constructor for servlet class.
      Parameters:
      name - the servlet name
      servlet - the servlet
    • ServletHolder

      public ServletHolder(Class<? extends jakarta.servlet.Servlet> servlet)
      Constructor for servlet class.
      Parameters:
      servlet - the servlet class
  • Method Details

    • getMultipartConfigElement

      public jakarta.servlet.MultipartConfigElement getMultipartConfigElement()
    • getUnavailableException

      public jakarta.servlet.UnavailableException getUnavailableException()
      Returns:
      The unavailable exception or null if not unavailable
    • setServlet

      public void setServlet(jakarta.servlet.Servlet servlet)
    • getInitOrder

      @ManagedAttribute(value="initialization order", readonly=true) 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.

      Parameters:
      order - the servlet init order
    • compareTo

      public int compareTo(ServletHolder sh)
      Comparator by init order.
      Specified by:
      compareTo in interface Comparable<ServletHolder>
    • 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.
    • getRoleLinks

      public Map<String,String> getRoleLinks()
    • getForcedPath

      @ManagedAttribute(value="forced servlet path", readonly=true) 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
      Description copied from class: AbstractLifeCycle
      Method to override to start the lifecycle
      Overrides:
      doStart in class BaseHolder<jakarta.servlet.Servlet>
      Throws:
      AbstractLifeCycle.StopException - If thrown, the lifecycle will immediately be stopped.
      Exception - If there was a problem starting. Will cause a transition to FAILED state
    • initialize

      public void initialize() throws Exception
      Description copied from class: BaseHolder
      Do any setup necessary after starting
      Overrides:
      initialize in class BaseHolder<jakarta.servlet.Servlet>
      Throws:
      Exception - if unable to initialize
    • doStop

      public void doStop() throws Exception
      Description copied from class: AbstractLifeCycle
      Method to override to stop the lifecycle
      Overrides:
      doStop in class BaseHolder<jakarta.servlet.Servlet>
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • destroyInstance

      public void destroyInstance(Object o)
      Overrides:
      destroyInstance in class Holder<jakarta.servlet.Servlet>
    • getServlet

      public jakarta.servlet.Servlet getServlet() throws jakarta.servlet.ServletException
      Get the servlet.
      Returns:
      The servlet
      Throws:
      jakarta.servlet.ServletException - if unable to init the servlet on first use
    • getServletInstance

      public jakarta.servlet.Servlet getServletInstance()
      Get the servlet instance (no initialization done).
      Returns:
      The servlet or null
    • checkServletType

      public void checkServletType() throws jakarta.servlet.UnavailableException
      Check to ensure class of servlet is acceptable.
      Throws:
      jakarta.servlet.UnavailableException - if Servlet class is not of type Servlet
    • isAvailable

      public boolean isAvailable()
      Returns:
      true if the holder is started and is not unavailable
    • initJspServlet

      protected void initJspServlet() throws Exception
      Throws:
      Exception - if unable to init the JSP Servlet
    • getRunAsRole

      @ManagedAttribute(value="role to run servlet as", readonly=true) public String getRunAsRole()
    • setRunAsRole

      public void setRunAsRole(String role)
    • prepare

      protected void prepare(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws jakarta.servlet.ServletException, jakarta.servlet.UnavailableException
      Prepare to service a request.
      Parameters:
      request - the request
      response - the response
      Throws:
      jakarta.servlet.ServletException - if unable to prepare the servlet
      jakarta.servlet.UnavailableException - if not available
    • handle

      public void handle(jakarta.servlet.ServletRequest request, jakarta.servlet.ServletResponse response) throws jakarta.servlet.ServletException, jakarta.servlet.UnavailableException, IOException
      Service a request with this servlet.
      Parameters:
      request - the request
      response - the response
      Throws:
      jakarta.servlet.ServletException - if unable to process the servlet
      jakarta.servlet.UnavailableException - if servlet is unavailable
      IOException - if unable to process the request or response
    • isJspServlet

      protected boolean isJspServlet()
    • isJspServlet

      protected boolean isJspServlet(String classname)
    • getNameOfJspClass

      public String getNameOfJspClass(String jsp)
      Parameters:
      jsp - the jsp-file
      Returns:
      the simple classname of the jsp
    • getPackageOfJspClass

      public String getPackageOfJspClass(String jsp)
    • getJspPackagePrefix

      public String getJspPackagePrefix()
      Get the package for all jsps.
      Returns:
      the package for all jsps
    • getClassNameForJsp

      public String getClassNameForJsp(String jsp)
      Parameters:
      jsp - the jsp-file from web.xml
      Returns:
      the fully qualified classname
    • appendPath

      protected void appendPath(StringBuffer path, String element)
      Concatenate an element on to fully qualified classname.
      Parameters:
      path - the path under construction
      element - the element of the name to add
    • getRegistration

      public ServletHolder.Registration getRegistration()
    • newInstance

      protected jakarta.servlet.Servlet newInstance() throws Exception
      Returns:
      the newly created Servlet instance
      Throws:
      jakarta.servlet.ServletException - if unable to create a new instance
      IllegalAccessException - if not allowed to create a new instance
      InstantiationException - if creating new instance resulted in error
      NoSuchMethodException - if creating new instance resulted in error
      InvocationTargetException - If creating new instance throws an exception
      Exception
    • createInstance

      protected jakarta.servlet.Servlet createInstance() throws Exception
      Overrides:
      createInstance in class BaseHolder<jakarta.servlet.Servlet>
      Throws:
      Exception
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
      Specified by:
      dump in interface Dumpable
      Overrides:
      dump in class BaseHolder<jakarta.servlet.Servlet>
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable
    • toString

      public String toString()
      Overrides:
      toString in class Holder<jakarta.servlet.Servlet>