users@glassfish.java.net

Re: If-Range Response

From: <glassfish_at_javadesktop.org>
Date: Mon, 10 Sep 2007 15:48:55 PDT

First, the mime-type and the settings seem to be ok. The reason file-cache-enable was "off" and not "false" is because I used the web admin console to change the values you cited.

Second, this is how I create my request. "fd" is an object of an inner class I use to hide the details of a file download. The getDownloadedBytes() method returns 0 before a download begins, and return the number of bytes already downloaded when resuming a broken download. The getDownloadSize() returns the full length of the static resource in number of bytes. The getETag() returns null before a download begins or returns the ETag for the previous attempt to download when resuming.

int startByte = fd.getDownloadedBytes ();
int endByte = fd.getDownloadSize ();
      
HttpURLConnection conn = (HttpURLConnection)url.openConnection ();
conn.setRequestProperty ("Range","bytes=" + startByte + "-" +
      ((endByte > startByte) ? endByte : ""));
      
// This request property will automatically restart the download
// if the target has changed
String etag = fd.getETag ();
if (null != etag){
   conn.setRequestProperty ("If-Range", etag);
}

I get an input stream from the connection to read all the bytes from and write them to a java.io.RandomAccessFile. This is the client code.

So, for a test I attempt to download a resource in the docroot/ folder. I let the download proceed for a few seconds and then cancel it, so it is incomplete. I then use cygwin to execute the "touch" utility on the resource being downloaded (this updates the modified date to cause the download start over from the beginning since the ETag will no longer match). I restart the download, going through the same code above to reestablish the connection, but as stated before the response is ok (http 200), its just the content of the connection (the input stream) is empty. The response from the server doesn't include the static resouce like the spec defines.
[Message sent by forum member 'martin_woolstenhulme' (martin_woolstenhulme)]

http://forums.java.net/jive/thread.jspa?messageID=234766