public interface

ServletModuleManager

com.atlassian.plugin.servlet.ServletModuleManager
Known Indirect Subclasses

Class Overview

The ServletModuleManager is responsible for servlets and filters - and their servlet contexts - defined in plugins. It is used by instances of the 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.

Summary

Public Methods
abstract void addFilterModule(ServletFilterModuleDescriptor descriptor)
Register a new filter plugin module.
abstract void addServletModule(ServletModuleDescriptor descriptor)
Register a new servlet plugin module.
abstract Iterable<Filter> getFilters(FilterLocation location, String pathInfo, FilterConfig filterConfig)
This method is deprecated. Since 2.5.0, use getFilters(FilterLocation, String, FilterConfig, FilterDispatcherCondition) instead
abstract Iterable<Filter> getFilters(FilterLocation location, String pathInfo, FilterConfig filterConfig, FilterDispatcherCondition condition)
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.
abstract HttpServlet getServlet(String path, ServletConfig servletConfig)
Return an instance of the HttpServlet that should be used to serve content matching the provided url path.
abstract void removeFilterModule(ServletFilterModuleDescriptor descriptor)
Remove a previously registered filter plugin module.
abstract void removeServletModule(ServletModuleDescriptor descriptor)
Remove a previously registered servlet plugin module.

Public Methods

public abstract void addFilterModule (ServletFilterModuleDescriptor descriptor)

Register a new filter plugin module.

Parameters
descriptor Details of what the filter class is and the path it should serve.

public abstract void addServletModule (ServletModuleDescriptor descriptor)

Register a new servlet plugin module.

Parameters
descriptor Details of what the servlet class is and the path it should serve.

public abstract Iterable<Filter> getFilters (FilterLocation location, String pathInfo, FilterConfig filterConfig)

This method is deprecated.
Since 2.5.0, use getFilters(FilterLocation, String, FilterConfig, FilterDispatcherCondition) instead

Returns the filters that have been registered to filter requests at the specified path matching the location in the filter stack. The filter dispatcher condition will be set to REQUEST.

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.
Returns
  • List of filters to be applied, already sorted by weight
Throws
ServletException Thrown if there is a problem initializing one of the filters to apply.

public abstract Iterable<Filter> getFilters (FilterLocation location, String pathInfo, FilterConfig filterConfig, FilterDispatcherCondition condition)

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
ServletException Thrown if there is a problem initializing one of the filters to apply.

public abstract HttpServlet getServlet (String path, ServletConfig servletConfig)

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
ServletException Thrown if there is a problem initializing the servlet to be returned.

public abstract void removeFilterModule (ServletFilterModuleDescriptor descriptor)

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.

public abstract void removeServletModule (ServletModuleDescriptor descriptor)

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.