Servlet Filter

The filter is still in it's early stages (as of version 0.45), but has some interesting applications and will be further developed in the future. Contrary to the servlet it intercepts image requests based on URL patterns and then decides whether to apply image filtering before returning the image or not. Given a particular image directory, i.e. "/products" in your web application, you can use the servlet filter to bulk format all the images at that location with a particular look and feel (using a custom filterchain). This document will explore how to use and configure the servlet filter.


 <filter>
     <filter-name>imageinterceptor</filter-name>
     <filter-class>org.jmage.mapper.InterceptorMapper</filter-class>
     <init-param>
         <param-name>products</param-name>
         <param-value>com.mycorp.jmagefilters.BrandedWaterMark</param-value>
     </init-param>
 </filter>

 <filter-mapping>
     <filter-name>imageinterceptor</filter-name>
     <url-pattern>/images/*</url-pattern>
 </filter-mapping>

Above configuration is a standard servlet 2.3 compliant filter config as found inside web.xml. First you need to specify the filter class and name, then a corresponding filter-mapping entry that tells the container which http requests to intercept. You can use the default pattern /images if that's where your webapp store all it's imagery. For performance reasons, it is not recommended you widen this filter to /* unless absolutely necessary.

Use one or more init-param blocks to tell the filter which transformation to apply for what requests. This is very simplistic at the moment and only checks whether the String you provide as key is contained in your request URL. If found, it will invoke the FilterChain specified in param value. There is planned future support for wildcards and more sophisticated ways of filter selection.