Had a smiliar problem here.

When using mod_jk, apache does not touch the headers created by Tomcat.

Solution:

I wrote a filter that changed the headers after returning from Tomcat
and installed this filter into Tomcat.

Servlets and filtering (Servlet-Spec 2.3):

http://java.sun.com/products/servlet/Filters.html

My sample-code (setting an Expires-Header):

=============[snip]=======================
package com.cr.manuals.filter;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class for Servlet: HeaderFilter
*
*/
public class HeaderFilter implements javax.servlet.Filter {
        
         private static String PARAM_ADD_TO_CURRENT_MONTH = 
"ADD_TO_CURRENT_MONTH";
         private FilterConfig filterConfig = null;
         private int months2Add = 0;
         /* (non-Java-doc)
          * @see javax.servlet.http.HttpServlet#HttpServlet()
         */
         public HeaderFilter() {
                 super();
         }                              

        /**
        * init() : init() method called when the filter is instantiated.
        * This filter is instantiated the first time j_security_check is
        * invoked for the application (When a protected servlet in the
        * application is accessed).
        */
        public void init(FilterConfig aFilterConfig) throws ServletException {
                filterConfig = aFilterConfig;
                months2Add = 
Integer.parseInt(filterConfig.getInitParameter(PARAM_ADD_TO_CURRENT_MONTH));
        }

        /**
        * destroy() : destroy() method called when the filter is taken
        * out of service.
        */
        public void destroy() {
                filterConfig = null;
        }

        /**
        * doFilter() : doFilter() method called before the servlet to
        * which this filteris mapped is invoked. Since this filter is
        * mapped to j_security_check,this method is called before
        * j_security_check action is posted.
        */
        public void doFilter(ServletRequest aRequest, ServletResponse aResponse,
                                                FilterChain chain) throws 
java.io.IOException, ServletException {

              //System.out.println ("******** filter *******");
        
                  HttpServletRequest request = (HttpServletRequest)aRequest;
              HttpServletResponse response = (HttpServletResponse)aResponse;
              // call next filter in the chain : let j_security_check 
authenticate
              // user
              response.setHeader("Expires", createExpiresHeader(months2Add));
              chain.doFilter(request, response);
        
        }
        /**
         * Create a String in the format EEE, d MMM yyyy HH:mm:ss z"
         * Example: Fri, 4 Aug 2006 09:07:44 CEST
         * The value of the init-parama ADD_TO_CURRENT_MONTH is added to the
         * month-field of the current date
         * @return
         */
        private String createExpiresHeader(int someMonths2Add) {
                SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy
HH:mm:ss z", Locale.US);
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.MONTH, someMonths2Add);
                long millis = cal.getTimeInMillis();
                Date d = new Date(millis);
                return sdf.format(d);
        }
}
=============[snap]=======================

HTH

Gregor
--
what's puzzlin' you, is the nature of my game
gpgp-fp: 79A84FA526807026795E4209D3B3FE028B3170B2
gpgp-key available @ http://pgpkeys.pca.dfn.de:11371

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to