Two Servlet Filters Every Web Application Should Have
Subject:   Caching saves no data
Date:   2003-11-25 21:21:41
From:   anonymous2
I cannot seem to get the caching solution to work.

I believe that the ByteArrayOutputStream is not getting any data when

CacheResponseWrapper wrappedResponse = new CacheResponseWrapper(response, baos);
chain.doFilter(req, wrappedResponse);

is executed. The file created contains no data :(. Tracing the program flow shows that both the CacheResponseWrapper and CacheResponseStream are created.

I am using tomcat 4.1.27, jdk1.4.1, I have followed all the instructions, any help much appreciated!

Full Threads Oldest First

Showing messages 1 through 6 of 6.

  • Problem with the ByteArrayOutputStream ...
    2003-11-27 03:07:07  anonymous2 [View]

    Hello !

    I am using jboss-3.2.1_tomcat-4.1.24 Bundle ...

    I have exactly the same problem ...
    The ByteArrayOutputStream is still empty after the :
    chain.doFilter(req, wrappedResponse);

    If i try :
    System.out.println("CacheFilter : BAOS Size = " + baos.size());

    I get : BAOS size = 0 ...

    So :
    FileOutputStream fos = new FileOutputStream(file);

    is only creating an empty cache ...

    I don't know where I missed something, so if you have a clue, tell me please ^_^

    • Problem solved ^_^
      2003-11-27 03:30:41  anonymous2 [View]

      Hello all !

      OK, problem solved ...
      In fact in the file web.xml :


      You need to declare your CacheFilter filter-mapping before your GZIPFilter filter-mapping ...

      And then everything is ok :)

      Thanks Jayson for your filters,

      • Problem solved ^_^
        2003-12-02 15:26:36  anonymous2 [View]

        I am glad your solution worked. However I must have another issue as I don't even have the GZIPFiler enabled. I have taken everything out of the web.xml except the cache filter and still no joy.
        • Problem solved
          2005-01-07 04:48:16  mcr [View]

          This also worked with Tomcat 5, but without
          requiring the clumsy empty file include:

          <% out.flush(); %>
        • Problem solved ^_^
          2005-01-06 12:54:28  mcr [View]

          I finally solved this problem by importing an empty html file with flush=true at the very end of each cached page, as so:

          • Problem solved ^_^
            2005-01-06 12:55:29  mcr [View]


            >jsp:include page="/include/empty.html" flush="true" /<