Package com.helger.servlet.mock
Class MockServletPool
- java.lang.Object
-
- com.helger.servlet.mock.MockServletPool
-
@ThreadSafe public class MockServletPool extends Object
A pool for registered servlets inside aMockServletContext.- Author:
- Philip Helger
-
-
Constructor Summary
Constructors Constructor Description MockServletPool(MockServletContext aSC)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description jakarta.servlet.ServletgetServletOfPath(String sPath)Find the servlet matching the specified path.voidinvalidate()Invalidate the servlet pool, by destroying all contained servlets.voidregisterServlet(Class<? extends jakarta.servlet.Servlet> aServletClass, String sServletPath, String sServletName)Register a new servlet without servlet init parametersvoidregisterServlet(Class<? extends jakarta.servlet.Servlet> aServletClass, String sServletPath, String sServletName, Map<String,String> aServletInitParams)Register a new servlet
-
-
-
Constructor Detail
-
MockServletPool
public MockServletPool(@Nonnull MockServletContext aSC)
-
-
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 benull.sServletPath- The path where the servlet should listen to requests. May neither benullnor empty.sServletName- The name of the servlet. May neither benullnor 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 benull.sServletPath- The path where the servlet should listen to requests. May neither benullnor empty.sServletName- The name of the servlet. May neither benullnor empty.aServletInitParams- An optional map of servlet init parameters. May benullor 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 benull.- Returns:
nullif noServletmatching 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.
-
-