Class ServletHandler

    • Field Detail

      • __DEFAULT_SERVLET

        public static final java.lang.String __DEFAULT_SERVLET
        See Also:
        Constant Field Values
      • _chainCache

        protected final java.util.concurrent.ConcurrentMap<java.lang.String,​javax.servlet.FilterChain>[] _chainCache
      • _chainLRU

        protected final java.util.Queue<java.lang.String>[] _chainLRU
    • Constructor Detail

      • ServletHandler

        public ServletHandler()
        Constructor.
    • Method Detail

      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.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 ContainerLifeCycle
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • isEnsureDefaultServlet

        public boolean isEnsureDefaultServlet()
        Returns:
        true if ServletHandler always has a default servlet, using ServletHandler.Default404Servlet if no other default servlet is configured.
      • setEnsureDefaultServlet

        public void setEnsureDefaultServlet​(boolean ensureDefaultServlet)
        Parameters:
        ensureDefaultServlet - true if ServletHandler always has a default servlet, using ServletHandler.Default404Servlet if no other default servlet is configured.
      • start

        protected void start​(LifeCycle l)
                      throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Starts the given lifecycle.
        Overrides:
        start in class ContainerLifeCycle
        Parameters:
        l - the lifecycle to start
        Throws:
        java.lang.Exception - if unable to start lifecycle
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Stops the managed lifecycle beans in the reverse order they were added.
        Overrides:
        doStop in class AbstractHandler
        Throws:
        java.lang.Exception
      • getHolderEntry

        @Deprecated
        public MappedResource<ServletHolder> getHolderEntry​(java.lang.String target)
        Deprecated.
        ServletHolder matching path.
        Parameters:
        target - Path within _context or servlet name
        Returns:
        PathMap Entries pathspec to ServletHolder
      • getServletContext

        public javax.servlet.ServletContext getServletContext()
      • getServletMapping

        public ServletMapping getServletMapping​(java.lang.String pathSpec)
        Get the ServletMapping matching the path
        Parameters:
        pathSpec - the path spec
        Returns:
        the servlet mapping for the path spec (or null if not found)
      • getServlets

        public java.util.List<ServletHolder> getServlets​(java.lang.Class<?> clazz)
      • getServlet

        public ServletHolder getServlet​(java.lang.String name)
      • getMappedServlet

        public MappedResource<ServletHolder> getMappedServlet​(java.lang.String target)
        ServletHolder matching path.
        Parameters:
        target - Path within _context or servlet name
        Returns:
        MappedResource to the ServletHolder. Named servlets have a null PathSpec
      • getFilterChain

        protected javax.servlet.FilterChain getFilterChain​(Request baseRequest,
                                                           java.lang.String pathInContext,
                                                           ServletHolder servletHolder)
      • invalidateChainsCache

        protected void invalidateChainsCache()
      • isAvailable

        public boolean isAvailable()
        Returns:
        true if the handler is started and there are no unavailable servlets
      • setStartWithUnavailable

        public void setStartWithUnavailable​(boolean start)
        Parameters:
        start - True if this handler will start with unavailable servlets
      • isAllowDuplicateMappings

        public boolean isAllowDuplicateMappings()
        Returns:
        the allowDuplicateMappings
      • setAllowDuplicateMappings

        public void setAllowDuplicateMappings​(boolean allowDuplicateMappings)
        Parameters:
        allowDuplicateMappings - the allowDuplicateMappings to set
      • isStartWithUnavailable

        public boolean isStartWithUnavailable()
        Returns:
        True if this handler will start with unavailable servlets
      • initialize

        public void initialize()
                        throws java.lang.Exception
        Initialize filters and load-on-startup servlets.
        Throws:
        java.lang.Exception - if unable to initialize
      • isFilterChainsCached

        public boolean isFilterChainsCached()
        Returns:
        whether the filter chains are cached.
      • addListener

        public void addListener​(ListenerHolder listener)
        Add a holder for a listener
        Parameters:
        listener - the listener for the holder
      • setListeners

        public void setListeners​(ListenerHolder[] listeners)
      • newServletHolder

        public ServletHolder newServletHolder​(Source source)
        Add a new servlet holder
        Parameters:
        source - the holder source
        Returns:
        the servlet holder
      • addServletWithMapping

        public ServletHolder addServletWithMapping​(java.lang.String className,
                                                   java.lang.String pathSpec)
        Convenience method to add a servlet.
        Parameters:
        className - the class name
        pathSpec - the path spec
        Returns:
        The servlet holder.
      • addServletWithMapping

        public ServletHolder addServletWithMapping​(java.lang.Class<? extends javax.servlet.Servlet> servlet,
                                                   java.lang.String pathSpec)
        Convenience method to add a servlet.
        Parameters:
        servlet - the servlet class
        pathSpec - the path spec
        Returns:
        The servlet holder.
      • addServletWithMapping

        public void addServletWithMapping​(ServletHolder servlet,
                                          java.lang.String pathSpec)
        Convenience method to add a servlet.
        Parameters:
        servlet - servlet holder to add
        pathSpec - servlet mappings for the servletHolder
      • addServlet

        public void addServlet​(ServletHolder holder)
        Convenience method to add a pre-constructed ServletHolder.
        Parameters:
        holder - the servlet holder
      • addServletMapping

        public void addServletMapping​(ServletMapping mapping)
        Convenience method to add a pre-constructed ServletMapping.
        Parameters:
        mapping - the servlet mapping
      • setServletSecurity

        public java.util.Set<java.lang.String> setServletSecurity​(javax.servlet.ServletRegistration.Dynamic registration,
                                                                  javax.servlet.ServletSecurityElement servletSecurityElement)
      • getFilter

        public FilterHolder getFilter​(java.lang.String name)
      • addFilterWithMapping

        public FilterHolder addFilterWithMapping​(java.lang.Class<? extends javax.servlet.Filter> filter,
                                                 java.lang.String pathSpec,
                                                 java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
        Convenience method to add a filter.
        Parameters:
        filter - class of filter to create
        pathSpec - filter mappings for filter
        dispatches - see FilterMapping.setDispatches(int)
        Returns:
        The filter holder.
      • addFilterWithMapping

        public FilterHolder addFilterWithMapping​(java.lang.String className,
                                                 java.lang.String pathSpec,
                                                 java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
        Convenience method to add a filter.
        Parameters:
        className - of filter
        pathSpec - filter mappings for filter
        dispatches - see FilterMapping.setDispatches(int)
        Returns:
        The filter holder.
      • addFilterWithMapping

        public void addFilterWithMapping​(FilterHolder holder,
                                         java.lang.String pathSpec,
                                         java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
        Convenience method to add a filter.
        Parameters:
        holder - filter holder to add
        pathSpec - filter mappings for filter
        dispatches - see FilterMapping.setDispatches(int)
      • addFilterWithMapping

        public FilterHolder addFilterWithMapping​(java.lang.Class<? extends javax.servlet.Filter> filter,
                                                 java.lang.String pathSpec,
                                                 int dispatches)
        Convenience method to add a filter.
        Parameters:
        filter - class of filter to create
        pathSpec - filter mappings for filter
        dispatches - see FilterMapping.setDispatches(int)
        Returns:
        The filter holder.
      • addFilterWithMapping

        public FilterHolder addFilterWithMapping​(java.lang.String className,
                                                 java.lang.String pathSpec,
                                                 int dispatches)
        Convenience method to add a filter.
        Parameters:
        className - of filter
        pathSpec - filter mappings for filter
        dispatches - see FilterMapping.setDispatches(int)
        Returns:
        The filter holder.
      • addFilterWithMapping

        public void addFilterWithMapping​(FilterHolder holder,
                                         java.lang.String pathSpec,
                                         int dispatches)
        Convenience method to add a filter.
        Parameters:
        holder - filter holder to add
        pathSpec - filter mappings for filter
        dispatches - see FilterMapping.setDispatches(int)
      • addFilter

        @Deprecated
        public FilterHolder addFilter​(java.lang.String className,
                                      java.lang.String pathSpec,
                                      java.util.EnumSet<javax.servlet.DispatcherType> dispatches)
        Convenience method to add a filter with a mapping
        Parameters:
        className - the filter class name
        pathSpec - the path spec
        dispatches - the dispatcher types for this filter
        Returns:
        the filter holder created
      • addFilter

        public void addFilter​(FilterHolder filter,
                              FilterMapping filterMapping)
        Convenience method to add a filter and mapping
        Parameters:
        filter - the filter holder
        filterMapping - the filter mapping
      • addFilter

        public void addFilter​(FilterHolder filter)
        Convenience method to add a preconstructed FilterHolder
        Parameters:
        filter - the filter holder
      • addFilterMapping

        public void addFilterMapping​(FilterMapping mapping)
        Convenience method to add a preconstructed FilterMapping
        Parameters:
        mapping - the filter mapping
      • prependFilterMapping

        public void prependFilterMapping​(FilterMapping mapping)
        Convenience method to add a preconstructed FilterMapping
        Parameters:
        mapping - the filter mapping
      • insertFilterMapping

        protected FilterMapping[] insertFilterMapping​(FilterMapping mapping,
                                                      int pos,
                                                      boolean before)
        Insert a filtermapping in the list
        Parameters:
        mapping - the FilterMapping to add
        pos - the position in the existing arry at which to add it
        before - if true, insert before pos, if false insert after it
        Returns:
        the new FilterMappings post-insert
      • updateNameMappings

        protected void updateNameMappings()
      • updateMappings

        protected void updateMappings()
      • notFound

        protected void notFound​(Request baseRequest,
                                javax.servlet.http.HttpServletRequest request,
                                javax.servlet.http.HttpServletResponse response)
                         throws java.io.IOException,
                                javax.servlet.ServletException
        Throws:
        java.io.IOException
        javax.servlet.ServletException
      • containsFilterHolder

        protected boolean containsFilterHolder​(FilterHolder holder)
      • containsServletHolder

        protected boolean containsServletHolder​(ServletHolder holder)
      • setFilterChainsCached

        public void setFilterChainsCached​(boolean filterChainsCached)
        Parameters:
        filterChainsCached - The filterChainsCached to set.
      • setFilterMappings

        public void setFilterMappings​(FilterMapping[] filterMappings)
        Parameters:
        filterMappings - The filterMappings to set.
      • setFilters

        public void setFilters​(FilterHolder[] holders)
      • setServletMappings

        public void setServletMappings​(ServletMapping[] servletMappings)
        Parameters:
        servletMappings - The servletMappings to set.
      • setServlets

        public void setServlets​(ServletHolder[] holders)
        Set Servlets.
        Parameters:
        holders - Array of servlets to define
      • getMaxFilterChainsCacheSize

        public int getMaxFilterChainsCacheSize()
        Returns:
        The maximum entries in a filter chain cache.
      • setMaxFilterChainsCacheSize

        public void setMaxFilterChainsCacheSize​(int maxFilterChainsCacheSize)
        Set the maximum filter chain cache size. Filter chains are cached if isFilterChainsCached() is true. If the max cache size is greater than zero, then the cache is flushed whenever it grows to be this size.
        Parameters:
        maxFilterChainsCacheSize - the maximum number of entries in a filter chain cache.