• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • ehcache-web
  • nrana
  • Reporter: ayreon
  • January 19, 2010
  • 0
  • Watchers: 2
  • April 14, 2010
  • March 16, 2010

Description

I’m trying to enable EHCache full pages caches within our app, but it seems to me that there is a serious bug in the implementation since when the Spring tries to add a header it throws the underlying exception,

after some debugging it’s not a bug suprise since net.sf.ehcache.constructs.web.GenericResponseWrapper.addHeader(String, String) expects an Integer value for each header key

public void addHeader(final String name, final String value) { final String[] header = new String[]{name, value}; headers.add(header); super.addHeader(name, value);

  Integer count = (Integer) headerTracker.get(name.toLowerCase());
    if (count == null) {
        count = new Integer(1);
    } else {
        count = new Integer(count.intValue() + 1);
    }
    headerTracker.put(name.toLowerCase(), count);
}

and of course it’s not true at all (e.g Pragma and others operates with String values)

the method net.sf.ehcache.constructs.web.GenericResponseWrapper.setHeader(String, String) puts the String value to headerTracker so it should be aware of this fact.

public void setHeader(final String name, final String value) { super.setHeader(name, value);

    Integer count = (Integer) headerTracker.get(name);
    if (count != null && count.intValue() > 0) {
        for (int i = headers.size() - 1; i >= 0; i--) {
            String[] header = (String[]) headers.get(i);
            String hName = header[0];
            if (hName.equalsIgnoreCase(name)) {
                if (count > 1) {
                    headers.remove(i);
                    count = count.intValue() - 1;
                    headerTracker.put(name.toLowerCase(), new Integer(count));
                } else {
                    ((String[]) headers.get(i))[1] = value;
                }

            }
        }
    } else {
        headerTracker.put(name.toLowerCase(), value);
    }
}

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer at net.sf.ehcache.constructs.web.GenericResponseWrapper.addHeader(GenericResponseWrapper.java:189) [ehcache-web-2.0.0.jar:na] at org.springframework.web.servlet.support.WebContentGenerator.preventCaching(WebContentGenerator.java:273) [spring-webmvc-2.5.6.jar:2.5.6] at org.springframework.web.servlet.support.WebContentGenerator.applyCacheSeconds(WebContentGenerator.java:346) [spring-webmvc-2.5.6.jar:2.5.6] at org.springframework.web.servlet.support.WebContentGenerator.checkAndPrepare(WebContentGenerator.java:255) [spring-webmvc-2.5.6.jar:2.5.6] at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:294) [spring-webmvc-2.5.6.jar:2.5.6] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) [spring-webmvc-2.5.6.jar:2.5.6] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) [spring-webmvc-2.5.6.jar:2.5.6] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571) [spring-webmvc-2.5.6.jar:2.5.6] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501) [spring-webmvc-2.5.6.jar:2.5.6] at javax.servlet.http.HttpServlet.service(HttpServlet.java:617) [servlet-api.jar:na] at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) [servlet-api.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) [catalina.jar:na] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na] at net.sf.ehcache.constructs.web.filter.CachingFilter.buildPage(CachingFilter.java:263) [ehcache-web-2.0.0.jar:na] at net.sf.ehcache.constructs.web.filter.CachingFilter.buildPageInfo(CachingFilter.java:216) [ehcache-web-2.0.0.jar:na] at net.sf.ehcache.constructs.web.filter.CachingFilter.doFilter(CachingFilter.java:182) [ehcache-web-2.0.0.jar:na] at net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java:86) [ehcache-web-2.0.0.jar:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na] at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:630) [catalina.jar:na] at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436) [catalina.jar:na] at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374) [catalina.jar:na] at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302) [catalina.jar:na] at org.tuckey.web.filters.urlrewrite.NormalRewrittenUrl.doRewrite(NormalRewrittenUrl.java:195) [urlrewritefilter-3.1.0.jar:3.1.0] at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:159) [urlrewritefilter-3.1.0.jar:3.1.0] at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141) [urlrewritefilter-3.1.0.jar:3.1.0] at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90) [urlrewritefilter-3.1.0.jar:3.1.0] at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:417) [urlrewritefilter-3.1.0.jar:3.1.0] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:109) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:278) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.concurrent.ConcurrentSessionFilter.doFilterHttp(ConcurrentSessionFilter.java:99) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175) [spring-security-core-2.0.5.RELEASE.jar:na] at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236) [spring-2.5.6.jar:2.5.6] at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167) [spring-2.5.6.jar:2.5.6] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na] at com.kiko.store.filters.KikoSecurityFilter.doFilter(KikoSecurityFilter.java:53) [KikoSecurityFilter.class:na] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96) [spring-2.5.6.jar:2.5.6] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) [spring-2.5.6.jar:2.5.6] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) [catalina.jar:na] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:na] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) [catalina.jar:na] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina.jar:na] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433) [catalina.jar:na] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) [catalina.jar:na] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina.jar:na] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina.jar:na] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286) [catalina.jar:na] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845) [tomcat-coyote.jar:na] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) [tomcat-coyote.jar:na] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) [tomcat-coyote.jar:na]

Comments

Ludovic Orban 2010-03-16

fixed ClassCastException and a few more related headers bugs

Eric Dalquist 2010-03-29

Any timeline on a ehcache-web 2.0.1 release that includes this fix? More critically prior to the SVN fix for this bug no headers added via the response.setHeader(String,String) API were cached.

Steve Harris 2010-03-30

If nothing surprising happens then monday.

Nitin Rana 2010-04-14

System test “testAddThenSetHeaders” and “testSetThenAddHeaders “ (ehcache-web_tests_JDK_1.6) are passing now.