2 Replies Latest reply on Jul 27, 2004 7:56 AM by geraldj

    option in jboss to force all to insert pragma headers

    geraldj

      I could be wrong but some time last year when browsing through out the Jboss site I found a document which showed me how Jboss could insert headers in the JSP as to stop browser caching. At the time I did not use it because I already inserted these headers into my JSP's and now when we are in the process of releasing a much larger project these feature would be very useful.

      I've looked throught out the whole site to see if I could find that document again but to no avail. Was I dreaming ?? Do I have to go back to the code to insert these lines again ?? Can some one tell if if this does really exist and if so where ??

      Gerald :>

        • 1. Re: option in jboss to force all to insert pragma headers
          starksm64

          A simple filter comes to mind:

          package filter;
          
          import java.io.IOException;
          import java.util.ArrayList;
          import java.util.Enumeration;
          import javax.servlet.Filter;
          import javax.servlet.FilterChain;
          import javax.servlet.FilterConfig;
          import javax.servlet.ServletException;
          import javax.servlet.ServletRequest;
          import javax.servlet.ServletResponse;
          import javax.servlet.http.HttpServletResponse;
          
          /** A servlet filter that simply adds all header specified in its config
          to replies the filter is mapped to. An example would be to set the cache
           control max age:
          
           <filter>
           <filter-name>CacheControlFilter</filter-name>
           <filter-class>filter.ReplyHeaderFilter</filter-class>
           <init-param>
           <param-name>Cache-Control</param-name>
           <param-value>max-age=3600</param-value>
           </init-param>
           </filter>
          
           <filter-mapping>
           <filter-name>CacheControlFilter</filter-name>
           <url-pattern>/images/*</url-pattern>
           </filter-mapping>
           <filter-mapping>
           <filter-name>CacheControlFilter</filter-name>
           <url-pattern>*.js</url-pattern>
           </filter-mapping>
          
          
           @author Scott.Stark@jboss.org
           @version $Revison:$
           */
          public class ReplyHeaderFilter implements Filter
          {
           String[][] replyHeaders = {{}};
          
           public void init(FilterConfig config)
           {
           Enumeration names = config.getInitParameterNames();
           ArrayList tmp = new ArrayList();
           while( names.hasMoreElements() )
           {
           String name = (String) names.nextElement();
           String value = config.getInitParameter(name);
           String[] pair = {name, value};
           tmp.add(pair);
           }
           replyHeaders = new String[tmp.size()][2];
           tmp.toArray(replyHeaders);
           }
          
           public void doFilter(ServletRequest request, ServletResponse response,
           FilterChain chain)
           throws IOException, ServletException
           {
           // Apply the headers
           HttpServletResponse httpResponse = (HttpServletResponse) response;
           for(int n = 0; n < replyHeaders.length; n ++)
           {
           String name = replyHeaders[n][0];
           String value = replyHeaders[n][1];
           httpResponse.addHeader(name, value);
           }
           chain.doFilter(request, response);
           }
          
           public void destroy()
           {
           }
          }
          



          • 2. Re: option in jboss to force all to insert pragma headers
            geraldj

            Thanks for the filter and will give it a go. Just out of curiosity was there ever a feature in previous releases of Jboss that did this ???

            Gerald :>