com.atlassian.plugin.servlet
Interface ServletModuleManager

All Known Implementing Classes:
DefaultServletModuleManager, ServletModuleManager

public interface ServletModuleManager

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.


Method Summary
 void addFilterModule(ServletFilterModuleDescriptor descriptor)
          Register a new filter plugin module.
 void addServletModule(ServletModuleDescriptor descriptor)
          Register a new servlet plugin module.
 java.lang.Iterable<javax.servlet.Filter> getFilters(FilterLocation location, java.lang.String pathInfo, javax.servlet.FilterConfig filterConfig)
          Returns the filters that have been registered to filter requests at the specified path matching the location in the filter stack.
 javax.servlet.http.HttpServlet getServlet(java.lang.String path, javax.servlet.ServletConfig servletConfig)
          Return an instance of the HttpServlet that should be used to serve content matching the provided url path.
 void removeFilterModule(ServletFilterModuleDescriptor descriptor)
          Remove a previously registered filter plugin module.
 void removeServletModule(ServletModuleDescriptor descriptor)
          Remove a previously registered servlet plugin module.
 

Method Detail

addServletModule

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.

getServlet

javax.servlet.http.HttpServlet getServlet(java.lang.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

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.

addFilterModule

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.

getFilters

java.lang.Iterable<javax.servlet.Filter> getFilters(FilterLocation location,
                                                    java.lang.String pathInfo,
                                                    javax.servlet.FilterConfig filterConfig)
                                                    throws javax.servlet.ServletException
Returns the filters that have been registered to filter requests at the specified path matching the location in the filter stack.

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

removeFilterModule

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.


Copyright © 2008 Atlassian Pty Ltd. All Rights Reserved.