Class DeferredDynamic

java.lang.Object
de.aristaflow.adept2.base.servletcontainer.demux.DeferredDynamic
All Implemented Interfaces:
WrapSupportingDynamic, jakarta.servlet.Registration, jakarta.servlet.Registration.Dynamic, jakarta.servlet.ServletRegistration, jakarta.servlet.ServletRegistration.Dynamic

public class DeferredDynamic extends Object implements WrapSupportingDynamic
This class wraps a dynamically added Servlet and allows to change initialisation parameters and URL patterns for the servlet. Since servlet registration is deferred (i. e. after the servlet context has already been initialised), this dynamic also initialises the servlet, i. e. performs servlet lifecycle tasks. Usually these tasks are handled by the servlet context of the servlet container.
  • Field Details

    • servlet

      protected final DynamicServlet servlet
      The servlet this DeferredDynamic handles and initialises.
    • demuxServlet

      protected final DemuxServlet demuxServlet
      The demultiplexing servlet that is used for demultiplexing requests to the dynamically added servlets. This handles the mapping.
    • servletContext

      protected jakarta.servlet.ServletContext servletContext
      The servlet context that creates this DeferredDynamic for initialising the servlet.
    • initParams

      protected final Map<String,String> initParams
      The parameters for the initialisation of the servlet of this DeferredDynamic. These are copied from the servlet context when creating this DeferredDynamic (i. e. when adding the servlet to the servlet context). Before initialising the servlet, additional init parameters can be added.
    • role

      protected String role
      The runAs role of this ServletRegistration.
    • initialised

      protected boolean initialised
      Whether the servlet has been initialised. If so, all set methods cannot be called any more but lead to an IllegalStateException.
  • Constructor Details

    • DeferredDynamic

      public DeferredDynamic(DynamicServlet servlet, DemuxServlet demuxServlet, jakarta.servlet.ServletContext servletContext, Map<String,String> contextInitParams)
      Creates a new DeferredDynamic for the designated servlet using the designated multiplexing servlet and having the designated (deferred) servlet context and init parameters. The init parameters may be changed until the servlet is initialised.
      Parameters:
      servlet - The servlet which is added to the designated servlet context which is about to be initialised and which can be configured via the created DeferredDynamic.
      demuxServlet - The demultiplexing servlet handling and forwarding incoming requests.
      servletContext - The context of the servlet.
      contextInitParams - The init parameters of the servlet context. These can be changed until the servlet is initialised.
  • Method Details

    • addMapping

      public Set<String> addMapping(String... urlPatterns)
      Specified by:
      addMapping in interface jakarta.servlet.ServletRegistration
    • removeMappings

      public void removeMappings()
      Remove all previously added URL mappings for this servlet.
    • getMappings

      public Collection<String> getMappings()
      Specified by:
      getMappings in interface jakarta.servlet.ServletRegistration
    • getRunAsRole

      public String getRunAsRole()
      Specified by:
      getRunAsRole in interface jakarta.servlet.ServletRegistration
    • getName

      public String getName()
      Specified by:
      getName in interface jakarta.servlet.Registration
    • getClassName

      public String getClassName()
      Specified by:
      getClassName in interface jakarta.servlet.Registration
    • setInitParameter

      public boolean setInitParameter(String name, String value)
      Specified by:
      setInitParameter in interface jakarta.servlet.Registration
    • getInitParameter

      public String getInitParameter(String name)
      Specified by:
      getInitParameter in interface jakarta.servlet.Registration
    • setInitParameters

      public Set<String> setInitParameters(Map<String,String> initParameters)
      Specified by:
      setInitParameters in interface jakarta.servlet.Registration
    • getInitParameters

      public Map<String,String> getInitParameters()
      Specified by:
      getInitParameters in interface jakarta.servlet.Registration
    • setAsyncSupported

      public void setAsyncSupported(boolean isAsyncSupported)
      Specified by:
      setAsyncSupported in interface jakarta.servlet.Registration.Dynamic
    • setLoadOnStartup

      public void setLoadOnStartup(int loadOnStartup)
      Specified by:
      setLoadOnStartup in interface jakarta.servlet.ServletRegistration.Dynamic
    • setServletSecurity

      public Set<String> setServletSecurity(jakarta.servlet.ServletSecurityElement constraint)
      Specified by:
      setServletSecurity in interface jakarta.servlet.ServletRegistration.Dynamic
    • setMultipartConfig

      public void setMultipartConfig(jakarta.servlet.MultipartConfigElement multipartConfig)
      Specified by:
      setMultipartConfig in interface jakarta.servlet.ServletRegistration.Dynamic
    • setRunAsRole

      public void setRunAsRole(String roleName)
      Specified by:
      setRunAsRole in interface jakarta.servlet.ServletRegistration.Dynamic
    • setWrappingServletContext

      public void setWrappingServletContext(jakarta.servlet.ServletContext wrapped, jakarta.servlet.ServletContext wrapper)
      Description copied from interface: WrapSupportingDynamic
      Set the designated wrapping servlet context if this Dynamic contains the designated wrapped servlet context.
      Specified by:
      setWrappingServletContext in interface WrapSupportingDynamic
      Parameters:
      wrapped - The wrapped servlet context this Dynamic may contain.
      wrapper - The wrapping servlet context to replace the servlet context within this Dynamic.
    • getServlet

      public jakarta.servlet.Servlet getServlet()
      Gets the servlet this Dynamic wraps.
      Returns:
      The servlet this Dynamic wraps.
    • init

      public void init(String hierContext) throws jakarta.servlet.ServletException
      Initialises the servlet of this DeferredDynamic. After this, the servlet is reachable and the set methods on this DeferredDynamic cannot be called any more.
      Parameters:
      hierContext - The hierarchical context of the servlet with trailing "/".
      Throws:
      jakarta.servlet.ServletException - If initialisation of the servlet fails, a ServletException will be thrown.
    • checkState

      protected void checkState()
      Checks the state by throwing an IllegalArgumentException if the servlet has already been initialised. This prevents calling methods that change data that is relevant for initialising the servlet, e. g. init parameters.