0 Replies Latest reply on Feb 22, 2012 12:47 AM by ivan_ra

    cache bug in jboss portal and gatein portlet

    ivan_ra

      in jboss and gatein portal richfaces cant be cached when user is logged in.

      This is initial discussion: https://community.jboss.org/thread/177949?tstart=0

      Bug is found for richfaces 3.3.3 but i think can be reproduced for 4.x because org.richfaces.resource.AbstractCacheableResource has similar code.

      The steps for reproduce bug are:

      • download portlet bridge 2.2 archive
      • deploy richFacesPortlet.war from portlet bridge archive (i used jboss portal 2.7.2 bundle and GateIn-3.1.0-FINAL-jbossas)
      • look at network activity (i did with firefox + firebug, the same result on any other browser). Just open page with richfaces portlet.

      When user is not logged in, all richfaces resources are caching well, and this is headers returned by server:

       

      Cache-Controlmax-age=86400
      Content-Typetext/javascript
      DateThu, 26 Jan 2012 17:57:39 GMT
      Expires27 Jan 2012 17:57:39 GMT
      Last-Modified26 Jan 2012 17:42:17 GMT
      ServerApache-Coyote/1.1
      X-Powered-ByServlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0

      This time all data come from saved cache.

      But when user is logged in all richfaces stuff come from network every time (more than 1.3 mb).

      This is headers returned by portal 2.7.2 when user logged in:

       

      Cache-Controlno-cache, max-age=86400
      Content-Typetext/javascript
      DateThu, 26 Jan 2012 18:26:49 GMT
      ExpiresThu, 01 Jan 1970 03:00:00 MSK, 27 Jan 2012 18:26:49 GMT
      Last-Modified26 Jan 2012 18:05:56 GMT
      PragmaNo-cache
      ServerApache-Coyote/1.1
      Transfer-Encodingchunked
      X-Powered-ByServlet 2.4; JBoss-4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181417)/JBossWeb-2.0

       

      The same problem with GateIn-3.1.0-FINAL-jbossas bundle, but now only one wrong header:

       

      Cache-Controlmax-age=86400
      Content-Typetext/javascript;charset=UTF-8
      DateSat, 28 Jan 2012 08:54:14 GMT
      Expires29 Jan 2012 08:54:14 GMT
      Last-Modified28 Jan 2012 08:51:11 GMT
      PragmaNo-cache
      ServerApache-Coyote/1.1
      Transfer-Encodingchunked
      X-Powered-ByServlet 2.5; JBoss-5.0/JBossWeb-2.1

       

      This header (Pragma) appears only when user is logged in, and again, all richfaces resources come through network.

       

      I did some debug and found that richfaces create good headers, but there is some code in portal which put wrong values into real response before richfaces. I cant find this code in portal sources, so maybe it is JBoss AS problem, or third party component.

       

      Gatein portal overwrite 2 wrong headers with values provided by richfaces, but "pragma" header is absent in richfaces response, and this way in secured portlets richfaces generate too much unnesessary traffic.

       

      The workaround for richfaces 3.3.3 is to set empty pragma for transportHeaders in method

      org.ajax4jsf.resource.InternetResourceBase.sendHeaders(ResourceContext context): add this string

              if (cached) {

                  ...

                  context.setHeader("Pragma", "");

              }

       

      the same workaround for richfaces 4.1: in method

      org.richfaces.resource.AbstractCacheableResource.addCacheControlResponseHeaders(...) add

                  if (maxAge > 0) {
                      headers.put("Cache-Control", "max-age=" + maxAge);
                      headers.put("Pragma", "");
                  }

       

      For GateIn this patch is enough, JBoss portal 2.7.2 requires some additional work to pach portal code, who interested can follow link on top