Skip to content

A Java Filter to transparently set response headers for any http request - a fork of ResponseHeaderFilter from http://code.google.com/p/responseheaderfilter

Notifications You must be signed in to change notification settings

krimdomu/tomcat-responseheaderfilter

Repository files navigation

Tomcat Filter to add Custom HTTP Response Header

This is a fork of http://code.google.com/p/responseheaderfilter.

DEPENDENCIES

  • commons-collections.jar

  • commons-lang.jar

  • tomcat6-servlet-2.5-api.jar

BUILD

Just clone the git repository and put the jars named in DEPENDENCIES into a folder named "lib". Then you can execute

ant compile
ant jar

CONFIGURATION

Copy the file response-header-filter-1.0.jar onto your server expand the classpath with it.

If you're using tanuki wrapper open your wrapper.conf and add the following entries:

wrapper.java.classpath.4=/usr/share/java/commons-collections.jar
wrapper.java.classpath.5=/usr/share/java/commons-lang.jar
wrapper.java.classpath.6=/usr/share/java/tomcat6-servlet-2.5-api.jar
wrapper.java.classpath.7=/usr/ahre/java/response-header-filter-1.0.jar

Now open your web.xml and add the following lines:

<filter>
  <filter-name>ResponseHeaderFilter</filter-name>
  <filter-class>com.avlesh.web.filter.responseheaderfilter.ResponseHeaderManagerFilter</filter-class>
  <init-param>
    <param-name>configFile</param-name>
    <param-value>/path/to/your/header-filter-conf.xml</param-value>
  </init-param>
</filter>
<filter-mapping>
  <filter-name>ResponseHeaderFilter</filter-name>
  <url-pattern>*</url-pattern>
</filter-mapping>

And create a configuration file for the header filter. For example /path/to/your/header-filter-conf.xml and add the following to it:

<?xml version="1.0" encoding="UTF-8" ?>
<response-header-mapper>
<!-- generic rule for all html requests -->
   <mapping url=".*">
      <default>
         <response-headers>
            <header key="X-ServedBy" value="FooBar"/>
         </response-headers>
      </default>
   </mapping>
</response-header-mapper>

About

A Java Filter to transparently set response headers for any http request - a fork of ResponseHeaderFilter from http://code.google.com/p/responseheaderfilter

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published