5 Replies Latest reply on Jan 16, 2012 3:19 PM by healeyb

    Possible to attach a filter to Resource Servlet (4.1.0.Final)?

    healeyb

      Is it possible to attach a filter to the Resource Servlet? I tried using:

       

      @WebFilter(filterName = "MyFilter", servletNames = {"AutoRegisteredEditorResourceServlet"})

       

      with no success. What I want to do is set some http response headers, such as Last-Modified,ETag and

      Cache-Control for richfaces resources. I have resource mapping enabled and am successfully loading

      packed/compressed resources, which is brilliant, but the files themselves (i.e. packed.js) reload every

      time the page loads.

       

      All other resources in the application go through a cache filter which sets up all the headers properly.

       

      Another thing that is of interest is how to get last modified times for files that are bundled within jars in my

      application, such as richfaces*.jar & jsf-*.jar.

       

      Thanks,

      Brendan.

       

      p.s. I should point out that I'm using glassfish in a non-tomcat configuration at present. I'm going to need

             to use tomcat soon for cluster load balancing, so I do realise that Tomcat provides me with more

             configuration options.

        • 1. Re: Possible to attach a filter to Resource Servlet (4.1.0.Final)?
          lfryc

          Hi Brendan,

           

          if files served by ResourceServlet are not getting appropriate headers setup, it's really an issue!

           

          Could you please file a JIRA describing your issue?

           

           

          Thanks,

           

          ~ Lukas

          • 2. Re: Possible to attach a filter to Resource Servlet (4.1.0.Final)?
            healeyb

            Lukas, ok I'll log a JIRA. Glassfish (without using Tomcat) doesn't seem to do a very good job of implementing the

            http protocol, basically. To workaround this I've implemented a caching filter which checks the 'date modified' of

            the dates of files in the filesystem and potentially sends a 304.

             

            The problem is that the filter is listening to Faces Servlet, but none of the RichFaces resource requests get routed

            this way. What I'm seeing is that whilst richfaces resources are getting added to the browser cache (type in

            about:cache in the url window), they're never used because Cache-Control is set to no-cache.

             

            The issue is then how did it get set to no-cache? I think it's just the default setting. Regardless of this it would be

            useful to have some control over these headers somehow.

            • 3. Re: Possible to attach a filter to Resource Servlet (4.1.0.Final)?
              lfryc

              Basically all RichFaces resources served by Faces Servlet have headers set appropriately for caching.

              (You can check it by removing your Filter and turning resourceMapping=false).

               

              I assume you have problems with ResourceServlet where resources does not go through RichFaces ResourceHandler, so headers are set as for any other JSF resource - which means (AFAIK) no caching at all.

              • 4. Re: Possible to attach a filter to Resource Servlet (4.1.0.Final)?
                lfryc

                Brendan, I have created the issue here:

                https://issues.jboss.org/browse/RF-11890

                • 5. Re: Possible to attach a filter to Resource Servlet (4.1.0.Final)?
                  healeyb

                  I've got this working, the key is that even though I'm using a servlet 3 container you need to manually

                  declare the Resource Servlet in the web.xml, even though it would auto-register without this:

                   

                  <servlet>

                          <servlet-name>Resource Servlet</servlet-name>

                          <servlet-class>org.richfaces.webapp.ResourceServlet</servlet-class>

                          <load-on-startup>1</load-on-startup>

                      </servlet>

                      <servlet-mapping>

                          <servlet-name>Resource Servlet</servlet-name>

                          <url-pattern>/org.richfaces.resources/*</url-pattern>

                  </servlet-mapping>

                   

                  then you can use:

                   

                  @WebFilter(filterName = "MyFilter", servletNames = {"Resource Servlet"})

                   

                  In glassfish 3.1.1 I get Cache-Control: no-cache on all my richfaces resources unless I set the

                  response header in a filter - what I have observed is that when I set ETag & Last-Modified headers

                  my settings don't take effect - they're overwritten somehow.

                   

                  Regards,

                  Brendan.