JDK-6577221 : JnlpDownloadServlet does not handle If-Modified-Since properly with jnlp files
  • Type: Bug
  • Component: deploy
  • Sub-Component: webstart
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-07-05
  • Updated: 2011-02-16
  • Resolved: 2007-07-09
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.6.0-dp"
Java(TM) SE Runtime Environment (build 1.6.0-dp-b88-34)
Java HotSpot(TM) Client VM (build 1.6.0-b88-17-release, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux phclx01 2.6.9-42.0.3.ELsmp #1 SMP Mon Sep 25 17:28:02 EDT 2006 i686 i686 i386 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
The JnlpResource.java file always checks the system time as the last modified value for .jnlp files and this is compared to the If-Modified-Since header in JnlpDownloadServlet.java.

**** JnlpResource.java:getLastModified ****

// URL resource is always a file:// URL
    long getLastModified(ServletContext context, URL resource, String path) {
	long lastModified = 0;
	URLConnection conn;
	try {
	    // Get last modified time
	    conn = resource.openConnection();
	    lastModified = conn.getLastModified();
	} catch (Exception e) {
	    // do nothing
	}
	
	if (lastModified == 0) {
	    // Arguably a bug in the JRE will not set the lastModified for file URLs, and
	    // always return 0. This is a workaround for that problem.
	    String filepath = context.getRealPath(path);
	    if (filepath != null) {
		File f = new File(filepath);
		if (f.exists()) {
		    lastModified = f.lastModified();
		}
	    }
	}
	return lastModified;
    }

**********


 When the file is returned by JnlpFileHandler the last modified header is properly set to the value in the TS field in the beginning of a .jnlp file if it exists, otherwise the last modified is set to the value in the JnlpResource. The Download servlet should compare the If-Modified-Since value against the TS field value in the file if it exists. If the file was moved to its current location in the file system after the date in TS field then the .jnlp file is always downloaded by the javaws client.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a Java Web Start application with TS values set to the last modifed time in the .jnlp files. Touch the files so that the system last modified time is after the value in the TS field. Use  a javaws client to download the application.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JnlpDownloadServlet should compare the If-Modified-Since value with the TS value inside the .jnlp file.
ACTUAL -
Use tcpmon or another monitoring device to verify that when you load the application with javaws the .jnlp files are downloaded and the Last Modified field of the response header is the same as the TS value in the file and the second time you run javaws with the same url it sends If-Modified-Since header with the same value as the last-modified but the file is still downloaded because the JnlpResource class uses the systems last modified value as the last modified time.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Don't use TS's in your jnlp files or modify the code to work as expected.