Class MockServletPool


  • @ThreadSafe
    public class MockServletPool
    extends Object
    A pool for registered servlets inside a MockServletContext.
    Author:
    Philip Helger
    • Method Detail

      • registerServlet

        public void registerServlet​(@Nonnull
                                    Class<? extends jakarta.servlet.Servlet> aServletClass,
                                    @Nonnull @Nonempty
                                    String sServletPath,
                                    @Nonnull @Nonempty
                                    String sServletName)
        Register a new servlet without servlet init parameters
        Parameters:
        aServletClass - The class of the servlet to be registered. May not be null.
        sServletPath - The path where the servlet should listen to requests. May neither be null nor empty.
        sServletName - The name of the servlet. May neither be null nor empty.
      • registerServlet

        public void registerServlet​(@Nonnull
                                    Class<? extends jakarta.servlet.Servlet> aServletClass,
                                    @Nonnull @Nonempty
                                    String sServletPath,
                                    @Nonnull @Nonempty
                                    String sServletName,
                                    @Nullable
                                    Map<String,​String> aServletInitParams)
        Register a new servlet
        Parameters:
        aServletClass - The class of the servlet to be registered. May not be null.
        sServletPath - The path where the servlet should listen to requests. May neither be null nor empty.
        sServletName - The name of the servlet. May neither be null nor empty.
        aServletInitParams - An optional map of servlet init parameters. May be null or empty.
      • getServletOfPath

        @Nullable
        public jakarta.servlet.Servlet getServletOfPath​(@Nullable
                                                        String sPath)
        Find the servlet matching the specified path.
        Parameters:
        sPath - The path, relative to the servlet context. May be null.
        Returns:
        null if no Servlet matching the specified path was found. If more than one matching servlet was found, the first one is returned.
      • invalidate

        public void invalidate()
        Invalidate the servlet pool, by destroying all contained servlets. Also the list of registered servlets is cleared.