Gaderian Servlet Filter

Gaderian includes a feature to streamline the use of Gaderian within a web application: a servlet filter that can automatically construct the Gaderian Registry and ensure that end-of-request thread cleanup occurs.

The filter class is GaderianFilter. It constructs a standard Gaderian Registry (and includes WEB-INF/gaderian/module.xml, if present) when initialized, and will shutdown the Registry when the containing application is undeployed.

Each request will be terminated with a call to the Registry's cleanupThread() method, which will cleanup any thread-local values, including service implementations that are bound to the current thread.

The GaderianFilter class includes a static method for accessing the Registry.

Deployment Descriptor

To make use of the filter, it must be declared inside the web deployment descriptor (web.xml). Filters can be attached to servlets, or URL patterns, or both. Here's an example:

<filter>
  <filter-name>GaderianFilter</filter-name>
  <filter-class>org.ops4j.gaderian.servlet.GaderianFilter</filter-class>
</filter>

<servlet>
  <servlet-name>MyServlet</servlet-name>
  <servlet-class>myco.servlets.MyServlet</servlet-class>
</servlet>

<filter-mapping>
  <filter-name>GaderianFilter</filter-name>
  <servlet-name>MyServlet</servlet-name>
</filter-mapping>