The filter utilities are intended to be developed further before use. These utilities don't provide a complete implementation. They support adding custom behaviour by allowing the extension of certain methods. An example of how they can be used is provided by the Content Negotiation filter. The goal of this package is to reduce the boilerplate code that you are required to write when implementing filters.


The GenericFilter abstract class provides default implementations for several of the methods of the servlet Filter interface. The init method provides a basic implementation that stores the FilterConfig object passed into it. The init method is made final to ensure that the FilterConfig object will always be set. To implement any custom configuration that is needed before the filter is called can be performed by overriding the new configureFilter method. The default implementation of the destroy method is an empty method that you can override. A public getter and setter is provided for the FilterConfig object. The setter stores the FilterConfig object in a protected field, filterConfig. The setter also stores the ServletContext that is passed in a protected field, context. These are provided as a protected field instead of getters and setters to provide lighter weight access.


The GenericHTTPFilter abstract class provides a convenient way of casting the ServletRequest and the ServletResponse object passed in when calling the filter to HttpServletRequest and HttpServletResponse. A final implementation of the doFilter method is provided that does this. If the objects cannot be cast a ServletException will be thrown. A new method doHTTPFilter abstract method is provided that takes the HttpServletRequest and HttpServletResponse objects. This can be overridden to implement the filter.