Java Servlet Filters are very powerful and have been around for a while and they are used for intercepting the requests and responses dynamically and can transform\modify response for different devices. The WCS framework allows programmers to extend this feature and use if solve various interesting problems.
I have to warn that servlet filter should only be used very carefully as every request/response goes through it and if not done right could impact the performance of the site.
There are 3 parts to writing a filter in commerce.
1. Defining the Filter in web.xml (Web Deployment descriptor)
2. Where to add filter mapping in web.xml The order of filter mapping specified in the web deployment descriptor is used for filter chaining. I have worked on a couple and have them before DynaCache filter and the rational behind that is, we wanted to intercept the request before it goes into the DynaCache filter.
All requests in commerce are processed through multiple filters. It is important to understand where you want to place the filter.
3. Writing the java code for XXBlockServletFilter by overriding the doFilter method: All the processing happens here so if you are using it for Mobile or XML for any ruby on rails front end or blocking certain kinds of commands.
For More information on Commerce flow of request: