Class DeferredDynamic

  • All Implemented Interfaces:
    WrapSupportingDynamic, javax.servlet.Registration, javax.servlet.Registration.Dynamic, javax.servlet.ServletRegistration, javax.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 Detail

      • 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 javax.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 Detail

      • DeferredDynamic

        public DeferredDynamic​(DynamicServlet servlet,
                               DemuxServlet demuxServlet,
                               javax.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 Detail

      • addMapping

        public Set<String> addMapping​(String... urlPatterns)
        Specified by:
        addMapping in interface javax.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 javax.servlet.ServletRegistration
      • getRunAsRole

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

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

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

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

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

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

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

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

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

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

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

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

        public void setWrappingServletContext​(javax.servlet.ServletContext wrapped,
                                              javax.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 javax.servlet.Servlet getServlet()
        Gets the servlet this Dynamic wraps.
        Returns:
        The servlet this Dynamic wraps.
      • init

        public void init​(String hierContext)
                  throws javax.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:
        javax.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.