Quick links
Getting started Filter parameters (web.xml) Sample confugiration Understanding the config Extending the FilterAPI Download Known Gotchas
Contribute
HowTo Report a bug
ResponseHeaderFilterResponseHeaderFilter is a Java Web Filter for any J2EE compliant web application server
... [More]
(such as Resin or Tomcat), which lets you transparently set response headers for any http request. ResponseHeaderFilter abstracts the responsibility of setting these header from your code, thereby making it easy to change header policies without changing any code.
Some of the most commonly used response headers that this filter can apply are:
Cache-Control: Caching instructions for the client and proxies. Content-Type: The mime type of the response. Content-Encoding: Type of encoding used in the response. Content-Length: Length of the response body in bytes. Expires: Date/time after which the response is considered stale. Set-Cookie: Cookies are headers too. (e.g Set-Cookie: cookieName=cookieValue; Max-Age=3600;)
Getting startedThe simplest way to make this filter work in you webapp, is to create a file called response-header-filter.xml in your project's WEB-INF directory. Add the response header directives for your url's in this file. Here's a small example:
post the creation of this file, you'll have to add this filter definition to your web.xml as underneath
ResponseHeaderFilter
com.avlesh.web.filter.responseheaderfilter.ResponseHeaderFilter
ResponseHeaderFilter
*
... and bingo your filter is already in action. Look at a detailed sample configuration, read further or extend this API to implement a custom behavior.
Filter ParametersThis filter comes with a default behaviour of reloading your filter configuration file if the file has been modified. By default, the lastModifiedTimestamp of the file is checked every 10 seconds. If the lastModifiedTimestamp value has changed (meaning that the file has been modified), the configuration file is processed again and new mapping rules come into effect for the filter.
You can change this duration, called as reloadCheckInterval, in the filter definition. Moreover the file name/path, called as configFile, can also be specified as one of the filter parameters. Underneath is a sample filter mapping definition.
ResponseHeaderFilter
*
reloadCheckInterval
0
configFile
/WEB-INF/path-to/the-filter/config-file.xml [Less]