Class DeferredServletContext

  • All Implemented Interfaces:
    DynamicServletContext, Serializable, javax.servlet.ServletContext

    public class DeferredServletContext
    extends Object
    implements DynamicServletContext, Serializable
    This servlet context provides the means for adding servlets after the parent servlet context has already been initialised. It is closely coupled to the corresponding servlet implementation which demultiplexes incoming requests to all servlets added to this context.

    This servlet context has a parent servlet context to which most of the methods are forwarded. This excludes the handling of init parameters and servlets:
    Init parameters added to this deferred servlet context will be merged with the init parameters of the parent servlet context. Therefore one cannot add an init parameter that has already been set for the parent servlet context.
    Servlets can be added any time. The corresponding DeferredDynamic allows for setting URL patterns as well as changing init parameters. Note that as soon as a DeferredDynamic has been created, its init parameters will be a snapshot of the init parameters of this (and the parent) servlet context. That is, changing the init parameters in the servlet context will not affect the init parameters of the DeferredDynamic and therefore of the ServletConfig.

    This servlet context can be used in two ways:

    • Instantiate it directly providing the parent servlet context: DeferredServletContext(ServletContext).
      This requires configuration in the init parameters of the parent servlet context. These are the mapping (e. g. servlet name and path) and whether the demultiplexing servlet should support asynchronism. The mapping has to end with /* to allow for the paths of sub servlets to be handled correctly. Async support will be required if any sub servlets should use async behaviour. The configuration is then used to instantiate and register the demultiplexing servlet.
    • Let the servlet container instantiate the demultiplexing servlet (e. g. via web.xml).
      In this case the demultiplexing servlet will instantiate the deferred servlet context (DeferredServletContext(ServletConfig, DemuxServlet)) providing its own servlet context as parent context. The URL mapping will be retrieved from the servlet context, i. e. the web.xml.
    See Also:
    Serialized Form
    • Field Detail

      • INIT_PARAM_DEMUX_SERVLET_MAPPING

        public static final String INIT_PARAM_DEMUX_SERVLET_MAPPING
        Init parameter name for the URL mapping of the demultiplexing servlet.
        See Also:
        Constant Field Values
      • INIT_PARAM_DEMUX_SERVLET_ASYNC_SUPPORTED

        public static final String INIT_PARAM_DEMUX_SERVLET_ASYNC_SUPPORTED
        Init parameter name for the boolean value whether the demultiplexing servlet should be marked as async supported. This is required in case dynamically addded servlets have/need async support.
        See Also:
        Constant Field Values
      • parentContext

        protected final javax.servlet.ServletContext parentContext
        The parent servlet context to which to delegate to.
      • innerContextPath

        protected final String innerContextPath
        The path of this context, i. e. the context for the inner servlets. This is the path of the outer servlet context combined with the servlet path, i. e. the mapping of the demultiplexing servlet.
      • servletPath

        protected final String servletPath
        The servlet path, i. e. the last part of the innerContextPath. This is without leading and trailing slashes. It will be appended to the path before delegating getRealPath(String)
      • demuxServlet

        protected final DemuxServlet demuxServlet
        The demultiplexing servlet which forwards to the servlets added via this context.
      • ownServlets

        protected final Map<String,​DeferredDynamic> ownServlets
        The servlets added dynamically via this context.
      • ownInitParams

        protected final Map<String,​String> ownInitParams
        The parameters set at this context. This will be merged with the init parameters of the parent servlet context. The names of this and the parameters of the parent are disjoint.
    • Constructor Detail

      • DeferredServletContext

        public DeferredServletContext​(javax.servlet.ServletContext parentContext)
                               throws ConfigurationException
        Creates a new servlet context with the designated servlet context as parent. This will also retrieve the configuration for the URL pattern and async support from the init parameters (of the parent servlet context) and use this to instantiate and register the corresponding multiplexing servlet. The default for async support is false, the mapping has to be provided.
        Parameters:
        parentContext - The servlet context used as parent of the created servlet context.
        Throws:
        ConfigurationException - If the mapping is not defined or does not end with /*, a ConfigurationException will be thrown.
      • DeferredServletContext

        public DeferredServletContext​(javax.servlet.ServletConfig config,
                                      DemuxServlet servlet)
                               throws javax.servlet.ServletException
        Creates a new servlet context for the designated demultiplexing servlet. This constructor is called by Servlet.init(ServletConfig) of the designated servlet. That is, the designated servlet is instantiated and handled by the servlet container.
        Parameters:
        config - The config of the designated servlet providing the outer servlet container as well as the servlet mapping.
        servlet - The demultiplexing servlet which forwards to the servlets added dynamically to this servlet context.
        Throws:
        javax.servlet.ServletException - If the mapping of the designated servlet does not exist (i. e. is not configured), a ServletException will be thrown.
    • Method Detail

      • getContextPath

        public String getContextPath()
        Specified by:
        getContextPath in interface javax.servlet.ServletContext
      • getContext

        public javax.servlet.ServletContext getContext​(String uripath)
        Specified by:
        getContext in interface javax.servlet.ServletContext
      • getMajorVersion

        public int getMajorVersion()
        Specified by:
        getMajorVersion in interface javax.servlet.ServletContext
      • getMinorVersion

        public int getMinorVersion()
        Specified by:
        getMinorVersion in interface javax.servlet.ServletContext
      • getEffectiveMajorVersion

        public int getEffectiveMajorVersion()
        Specified by:
        getEffectiveMajorVersion in interface javax.servlet.ServletContext
      • getEffectiveMinorVersion

        public int getEffectiveMinorVersion()
        Specified by:
        getEffectiveMinorVersion in interface javax.servlet.ServletContext
      • getMimeType

        public String getMimeType​(String file)
        Specified by:
        getMimeType in interface javax.servlet.ServletContext
      • getResourcePaths

        public Set<String> getResourcePaths​(String path)
        Specified by:
        getResourcePaths in interface javax.servlet.ServletContext
      • getResourceAsStream

        public InputStream getResourceAsStream​(String path)
        Specified by:
        getResourceAsStream in interface javax.servlet.ServletContext
      • getRequestDispatcher

        public javax.servlet.RequestDispatcher getRequestDispatcher​(String path)
        Specified by:
        getRequestDispatcher in interface javax.servlet.ServletContext
      • getNamedDispatcher

        public javax.servlet.RequestDispatcher getNamedDispatcher​(String name)
        Specified by:
        getNamedDispatcher in interface javax.servlet.ServletContext
      • getServlet

        public javax.servlet.Servlet getServlet​(String name)
                                         throws javax.servlet.ServletException
        Specified by:
        getServlet in interface javax.servlet.ServletContext
        Throws:
        javax.servlet.ServletException
      • getServlets

        public Enumeration<javax.servlet.Servlet> getServlets()
        Specified by:
        getServlets in interface javax.servlet.ServletContext
      • getServletNames

        public Enumeration<String> getServletNames()
        Specified by:
        getServletNames in interface javax.servlet.ServletContext
      • log

        public void log​(String msg)
        Specified by:
        log in interface javax.servlet.ServletContext
      • log

        public void log​(Exception exception,
                        String msg)
        Specified by:
        log in interface javax.servlet.ServletContext
      • log

        public void log​(String message,
                        Throwable throwable)
        Specified by:
        log in interface javax.servlet.ServletContext
      • getRealPath

        public String getRealPath​(String path)
        Specified by:
        getRealPath in interface javax.servlet.ServletContext
      • getServerInfo

        public String getServerInfo()
        Specified by:
        getServerInfo in interface javax.servlet.ServletContext
      • getInitParameter

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

        public Enumeration<String> getInitParameterNames()
        This includes the init parameter names of the parent servlet context as well as the additional init parameter names set for this servlet context.
        Specified by:
        getInitParameterNames in interface javax.servlet.ServletContext
      • setInitParameter

        public boolean setInitParameter​(String name,
                                        String value)
        This will only set the designated init parameter if there is no init parameter of the same name.
        Specified by:
        setInitParameter in interface javax.servlet.ServletContext
      • getAttribute

        public Object getAttribute​(String name)
        Specified by:
        getAttribute in interface javax.servlet.ServletContext
      • getAttributeNames

        public Enumeration<String> getAttributeNames()
        Specified by:
        getAttributeNames in interface javax.servlet.ServletContext
      • setAttribute

        public void setAttribute​(String name,
                                 Object object)
        Specified by:
        setAttribute in interface javax.servlet.ServletContext
      • removeAttribute

        public void removeAttribute​(String name)
        Specified by:
        removeAttribute in interface javax.servlet.ServletContext
      • getServletContextName

        public String getServletContextName()
        Specified by:
        getServletContextName in interface javax.servlet.ServletContext
      • addServlet

        public DeferredDynamic addServlet​(String servletName,
                                          String className)
        Specified by:
        addServlet in interface javax.servlet.ServletContext
      • addServlet

        public DeferredDynamic addServlet​(String servletName,
                                          javax.servlet.Servlet servlet)
        Specified by:
        addServlet in interface javax.servlet.ServletContext
      • addJspFile

        public javax.servlet.ServletRegistration.Dynamic addJspFile​(String servletName,
                                                                    String jspFile)
        Specified by:
        addJspFile in interface javax.servlet.ServletContext
      • addServlet

        public DeferredDynamic addServlet​(String servletName,
                                          Class<? extends javax.servlet.Servlet> servletClass)
        Specified by:
        addServlet in interface javax.servlet.ServletContext
      • removeServlet

        public boolean removeServlet​(String servletName)
        Description copied from interface: DynamicServletContext
        Removes the servlet with the designated name.
        Specified by:
        removeServlet in interface DynamicServletContext
        Parameters:
        servletName - The name of the servlet which to remove.
        Returns:
        Whether a servlet of the designated name was registered and has been removed by this call.
      • createServlet

        public <T extends javax.servlet.Servlet> T createServlet​(Class<T> clazz)
                                                          throws javax.servlet.ServletException
        Specified by:
        createServlet in interface javax.servlet.ServletContext
        Throws:
        javax.servlet.ServletException
      • getServletRegistration

        public javax.servlet.ServletRegistration getServletRegistration​(String servletName)
        Specified by:
        getServletRegistration in interface javax.servlet.ServletContext
      • getServletRegistrations

        public Map<String,​? extends javax.servlet.ServletRegistration> getServletRegistrations()
        Specified by:
        getServletRegistrations in interface javax.servlet.ServletContext
      • addFilter

        public javax.servlet.FilterRegistration.Dynamic addFilter​(String filterName,
                                                                  String className)
        Specified by:
        addFilter in interface javax.servlet.ServletContext
      • addFilter

        public javax.servlet.FilterRegistration.Dynamic addFilter​(String filterName,
                                                                  javax.servlet.Filter filter)
        Specified by:
        addFilter in interface javax.servlet.ServletContext
      • addFilter

        public javax.servlet.FilterRegistration.Dynamic addFilter​(String filterName,
                                                                  Class<? extends javax.servlet.Filter> filterClass)
        Specified by:
        addFilter in interface javax.servlet.ServletContext
      • createFilter

        public <T extends javax.servlet.Filter> T createFilter​(Class<T> clazz)
                                                        throws javax.servlet.ServletException
        Specified by:
        createFilter in interface javax.servlet.ServletContext
        Throws:
        javax.servlet.ServletException
      • getFilterRegistration

        public javax.servlet.FilterRegistration getFilterRegistration​(String filterName)
        Specified by:
        getFilterRegistration in interface javax.servlet.ServletContext
      • getFilterRegistrations

        public Map<String,​? extends javax.servlet.FilterRegistration> getFilterRegistrations()
        Specified by:
        getFilterRegistrations in interface javax.servlet.ServletContext
      • getSessionCookieConfig

        public javax.servlet.SessionCookieConfig getSessionCookieConfig()
        Specified by:
        getSessionCookieConfig in interface javax.servlet.ServletContext
      • setSessionTrackingModes

        public void setSessionTrackingModes​(Set<javax.servlet.SessionTrackingMode> sessionTrackingModes)
        Specified by:
        setSessionTrackingModes in interface javax.servlet.ServletContext
      • getDefaultSessionTrackingModes

        public Set<javax.servlet.SessionTrackingMode> getDefaultSessionTrackingModes()
        Specified by:
        getDefaultSessionTrackingModes in interface javax.servlet.ServletContext
      • getEffectiveSessionTrackingModes

        public Set<javax.servlet.SessionTrackingMode> getEffectiveSessionTrackingModes()
        Specified by:
        getEffectiveSessionTrackingModes in interface javax.servlet.ServletContext
      • addListener

        public void addListener​(String className)
        Specified by:
        addListener in interface javax.servlet.ServletContext
      • addListener

        public <T extends EventListener> void addListener​(T t)
        Specified by:
        addListener in interface javax.servlet.ServletContext
      • addListener

        public void addListener​(Class<? extends EventListener> listenerClass)
        Specified by:
        addListener in interface javax.servlet.ServletContext
      • createListener

        public <T extends EventListener> T createListener​(Class<T> clazz)
                                                   throws javax.servlet.ServletException
        Specified by:
        createListener in interface javax.servlet.ServletContext
        Throws:
        javax.servlet.ServletException
      • getJspConfigDescriptor

        public javax.servlet.descriptor.JspConfigDescriptor getJspConfigDescriptor()
        Specified by:
        getJspConfigDescriptor in interface javax.servlet.ServletContext
      • getClassLoader

        public ClassLoader getClassLoader()
        Specified by:
        getClassLoader in interface javax.servlet.ServletContext
      • declareRoles

        public void declareRoles​(String... roleNames)
        Specified by:
        declareRoles in interface javax.servlet.ServletContext
      • getVirtualServerName

        public String getVirtualServerName()
        Specified by:
        getVirtualServerName in interface javax.servlet.ServletContext
      • getSessionTimeout

        public int getSessionTimeout()
        Specified by:
        getSessionTimeout in interface javax.servlet.ServletContext
      • setSessionTimeout

        public void setSessionTimeout​(int sessionTimeout)
        Specified by:
        setSessionTimeout in interface javax.servlet.ServletContext
      • getRequestCharacterEncoding

        public String getRequestCharacterEncoding()
        Specified by:
        getRequestCharacterEncoding in interface javax.servlet.ServletContext
      • setRequestCharacterEncoding

        public void setRequestCharacterEncoding​(String encoding)
        Specified by:
        setRequestCharacterEncoding in interface javax.servlet.ServletContext
      • getResponseCharacterEncoding

        public String getResponseCharacterEncoding()
        Specified by:
        getResponseCharacterEncoding in interface javax.servlet.ServletContext
      • setResponseCharacterEncoding

        public void setResponseCharacterEncoding​(String encoding)
        Specified by:
        setResponseCharacterEncoding in interface javax.servlet.ServletContext
      • getInitParams

        protected Map<String,​String> getInitParams()
        Gets the current init parameters of this servlet context as well as the ones from the parent servlet context.
        Returns:
        The current init parameters of this servlet context as well as the ones from the parent servlet context.