tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 12222] New: - TC Returns Stale Content
Date Mon, 02 Sep 2002 03:36:27 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12222>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12222

TC Returns Stale Content

           Summary: TC Returns Stale Content
           Product: Tomcat 4
           Version: 4.1.9
          Platform: All
        OS/Version: Windows NT/2K
            Status: UNCONFIRMED
          Severity: Normal
          Priority: Other
         Component: Connector:Coyote HTTP/1.1
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: tony@absolutejava.com


This problem existed with the old HTTP/1.1 Connector. It's "better" now with 
Coyote but still seems to exist.

I'm running TC 4.1.9, using the CoyoteConnector on Win 2k, SP3. The JDK is 
1.4.1.

Here's the issue....

This is a very simple situation. I have a Java client program (see code below) 
that performs the following steps:

1. Writes a file to a web context directory.
2. Uses a URLConnection to request the file in #1 from TC.
3. Sleeps for a few milliseconds.
4. Overwrites the file in #1 with new contents.
5. Uses a URLConnection to request the file in #1 from TC.


The expected behavior is for the data returned in step 5 to *always* be what 
was written in step 4, even if the sleep time is zero seconds.

In step 5, I find that Tomcat is returning the contents of the file that was 
written in step 1 -- BUT ONLY IF THE SLEEP TIME IS LESS THAN ABOUT 1 SECOND. If 
I sleep for 1 or more second, then the contents returned in step 5 is that 
which was written in step 4, which is what I would expect.

You can adjust the sleep time with the command line argument (number of millis).

The code below includes the small client that connects to Tomcat. Notice 
the "Cache-Control" header is set to "max-age=0" which should eliminate any 
caching on Tomcat. Just for grins, "Pragma:no-cache" is used too (although that 
shouldn't matter). Since I'm connecting directly to Tomcat (i.e., localhost) 
there is no proxy involved. I've checked the HTTP headers using a sniffer and 
they look fine.

BTW, using Apache rather than TC does not produce this problem -- even if the 
sleep time is zero, Apache returns the contents written in step 4.

Here is the client code....If you run this make sure you are writing the file 
to the same directory from which TC will serve it (obviously).

Thanks,

Tony
====================================================
import java.io.*;
import java.net.*;

public class TestURL {
  public static void writeToFile (String filename, String text)
  throws IOException {
    FileWriter fw = new FileWriter(filename);
    PrintWriter pw = new PrintWriter(fw);
    pw.print(text);
    pw.close();
    System.out.println ("writeToFile() wrote: " + filename);
    System.out.println ("writeToFile() text: " + "'" + text + "'");
    System.out.println ("---");
  } // writeToFile()


  public static String readURL (String url)
  throws IOException, MalformedURLException {
    StringBuffer sb = new StringBuffer("");
    URL srcurl = new URL(url);
    URLConnection urlc = srcurl.openConnection();
    urlc.setDoInput(true);
    urlc.setUseCaches(false);
    urlc.setDefaultUseCaches(false);
    urlc.setRequestProperty("Cache-Control", "max-age=0");
    urlc.setRequestProperty("Cache-Control", "no-cache");
    urlc.setRequestProperty("Cache-Control", "no-store");
    urlc.setRequestProperty("Pragma", "no-cache");

    InputStream is = urlc.getInputStream();
    InputStreamReader isr = new InputStreamReader(is);
    char[] buffer = new char[100];
    int charCount = 0;
    while((charCount = isr.read(buffer, 0, buffer.length)) != -1)
      sb.append(buffer, 0, charCount);

    isr.close();

    System.out.println ("readURL() read: " + url);
    System.out.println ("readURL() text: " + "'" + sb.toString() + "'");
    System.out.println ("---");

    return sb.toString();
  } // readURL()


  public static void main (String[] args)
  throws Exception {
    int sleepTime = 1000;

    if (args.length >= 1)
      sleepTime = Integer.parseInt (args[0]);

    System.out.println ("----- TOMCAT TEST -----");
    String basedir = "C:\\Development\\Projects\\Tester\\Servlets\\web\\junk\\";
    String baseurl  = "http://localhost/t/junk/";
    String testfile = "testurl.txt";
    String first   = "The first text";
    String second  = "The second text";

    String filepath = basedir + testfile;
    String fileurl  = baseurl + testfile;

    writeToFile(filepath, first);
    String s1 = readURL(fileurl);

    System.out.println ("Sleeping " + sleepTime + " milliseconds...");
    Thread.sleep(sleepTime);

    writeToFile(filepath, second);
    String s2 = readURL(fileurl);

    if(s2.equals(second))
      System.out.println("The second file was properly served.");
    else
      System.out.println("The second file was *NOT* properly served.");
  } // main()
} // TestURL()

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message