Interface ServletModuleManager
- All Known Implementing Classes:
DefaultServletModuleManager
ServletModuleContainerServlet and ServletFilterModuleContainerFilter
to lookup, create and wrap the filters and servlets defined in plugins.
When the first Filter or Servlet is first accessed in a plugin, a new ServletContext is
created for all the modules in the plugin to share. This is done by wrapping the applications
ServletContext, creating a map of attributes that are local to the plugin that are shadowed by the
applications ServletContext attributes, merging any servlet context init parameters from the plugin and the
application, and then running through any ServletContextListeners defined by the plugin has calling their
contextInitialized() methods.
The shadowing of the the plugins ServletContexts attributes are shadowed by the applications attributes
means that if an attribute does not exist in the plugin local attribute map, the applications attributes will be
returned. The plugin is thereby prevented from modifying the base applications context attributes on an application
wide scope and can instead only change them, but not remove them, on a local scope.
The init parameters in the plugin will override parameters from the base applications servlet init parameters that have the same name.
During the creation of Filters and Servlets, the FilterConfig and ServletConfig provided to
Filters and Servlets contain the plugin local ServletContext, as described above,
and provides access to the init parameters defined in the plugin xml for the Filter or Servlet.
After being created, the filters and servlets are wrapped to ensure the the init(), service(), doFilter(),
and destroy() methods and other methods defined in the Filter and Servlet interfaces are executed in the plugins
ClassLoader.
The plugins ServletContext is not destroyed until the plugin is disabled. It is also at this time that any
ServletContextListeners will have their contextDestroyed() methods called.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddFilterModule(ServletFilterModuleDescriptor descriptor) Register a new filter plugin module.voidaddServlet(Plugin plugin, String servletName, String className) voidaddServlet(Plugin plugin, String servletName, javax.servlet.http.HttpServlet servlet, javax.servlet.ServletContext servletContext) To be invoked byPluginServletContextWrapper.addServlet(String, javax.servlet.Servlet).voidaddServletModule(ServletModuleDescriptor descriptor) Register a new servlet plugin module.Iterable<javax.servlet.Filter>getFilters(FilterLocation location, String pathInfo, javax.servlet.FilterConfig filterConfig, FilterDispatcherCondition condition) Deprecated.since 4.6.0.Iterable<javax.servlet.Filter>getFilters(FilterLocation location, String pathInfo, javax.servlet.FilterConfig filterConfig, javax.servlet.DispatcherType dispatcher) Returns the filters that have been registered to filter requests at the specified path matching the location in the filter stack and registered for the specific dispatcher condition.javax.servlet.http.HttpServletgetServlet(String path, javax.servlet.ServletConfig servletConfig) Return an instance of the HttpServlet that should be used to serve content matching the provided url path.voidremoveFilterModule(ServletFilterModuleDescriptor descriptor) Remove a previously registered filter plugin module.voidremoveServletModule(ServletModuleDescriptor descriptor) Remove a previously registered servlet plugin module.
-
Method Details
-
addServletModule
Register a new servlet plugin module.- Parameters:
descriptor- Details of what the servlet class is and the path it should serve.
-
getServlet
javax.servlet.http.HttpServlet getServlet(String path, javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException Return an instance of the HttpServlet that should be used to serve content matching the provided url path.- Parameters:
path- Path of the incoming request to serve.servletConfig- ServletConfig given to the delegating servlet.- Returns:
- HttpServlet that has been registered to serve up content matching the passed in path.
- Throws:
javax.servlet.ServletException- Thrown if there is a problem initializing the servlet to be returned.
-
removeServletModule
Remove a previously registered servlet plugin module. Requests that come in on the path described in the descriptor will no longer be served.- Parameters:
descriptor- Details of what servlet module to remove.
-
addFilterModule
Register a new filter plugin module.- Parameters:
descriptor- Details of what the filter class is and the path it should serve.
-
getFilters
@Deprecated Iterable<javax.servlet.Filter> getFilters(FilterLocation location, String pathInfo, javax.servlet.FilterConfig filterConfig, FilterDispatcherCondition condition) throws javax.servlet.ServletException Deprecated.since 4.6.0. UsegetFilters(FilterLocation, String, FilterConfig, DispatcherType)instead.Returns the filters that have been registered to filter requests at the specified path matching the location in the filter stack and registered for the specific dispatcher condition.- Parameters:
location- Place in the applications filter stack the filters should be applied.pathInfo- Path of the incoming request to filter.filterConfig- FilterConfig given to the delegating filter.condition- The dispatcher tag that filters have been registered to. Cannot be null.- Returns:
- List of filters to be applied, already sorted by weight
- Throws:
javax.servlet.ServletException- Thrown if there is a problem initializing one of the filters to apply.- Since:
- 2.5.0
-
getFilters
Iterable<javax.servlet.Filter> getFilters(FilterLocation location, String pathInfo, javax.servlet.FilterConfig filterConfig, javax.servlet.DispatcherType dispatcher) Returns the filters that have been registered to filter requests at the specified path matching the location in the filter stack and registered for the specific dispatcher condition.- Parameters:
location- Place in the applications filter stack the filters should be applied.pathInfo- Path of the incoming request to filter.filterConfig- FilterConfig given to the delegating filter.dispatcher- The dispatcher that filters have been registered to. Cannot be null.- Returns:
- List of filters to be applied, already sorted by weight
- Since:
- 4.6.0
-
removeFilterModule
Remove a previously registered filter plugin module. Requests that come in on the path described in the descriptor will no longer be served.- Parameters:
descriptor- Details of what filter module to remove.
-
addServlet
To be invoked byPluginServletContextWrapper.addServlet(String, String)andPluginServletContextWrapper.addServlet(String, Class).Module containing the servlet will use
servletNamefor:- key, with "-servlet" appended
- name, with "Servlet" appended
- url-pattern, with "/" prepended
classNamewill be instantiated and initialised on first use.- Parameters:
plugin- mandatoryservletName- mandatoryclassName- mandatory
-
addServlet
void addServlet(Plugin plugin, String servletName, javax.servlet.http.HttpServlet servlet, javax.servlet.ServletContext servletContext) To be invoked byPluginServletContextWrapper.addServlet(String, javax.servlet.Servlet).Module containing the servlet will use
servletNamefor:- key, with "-servlet" appended
- name, with "Servlet" appended
- url-pattern, with "/" prepended
servletwill be initialised on first use.- Parameters:
plugin- mandatoryservletName- mandatoryservlet- mandatoryservletContext- mandatory
-