Skip to main content

If-Range Response

4 replies [Last post]
martin_woolstenhulme
Offline
Joined: 2007-09-10

When making a request with "If-Range" using the "ETag" provided by the server (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) for a static resource the response should include the partial content of the specified "Range" or the full content of the static resource being requesting. However, it doesn't appear that the full content is being returned when requesting a static resource that has changed.

I'm trying to create a simple class to manage downloads which must be able to resume downloads. Getting a download to resume works well enough, but when I interrupt my download, touch the file being downloaded from the server, and then restart the download I get the issue mentioned above. The response code is correct "200", but the "Content-Length" returned is zero. I'm using the "Sun Java System Application Server Platform Edition 9.0_01" as my server.

I've also looked into the source code, and the only place I could find source code handling the "If-Range" header was in org.apache.catalina.servlets.DefaultServlet. I think this is a potential issue but perhaps I misunderstand how the caching mechanism is supposed to work.

Is this in the right place to pursue this issue or should I send this to a mailing list (and which one is most appropriate)?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Jeanfrancois Arcand

Hi,

glassfish@javadesktop.org wrote:
> When making a request with "If-Range" using the "ETag" provided by the server (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html) for a static resource the response should include the partial content of the specified "Range" or the full content of the static resource being requesting. However, it doesn't appear that the full content is being returned when requesting a static resource that has changed.
>
> I'm trying to create a simple class to manage downloads which must be able to resume downloads. Getting a download to resume works well enough, but when I interrupt my download, touch the file being downloaded from the server, and then restart the download I get the issue mentioned above. The response code is correct "200", but the "Content-Length" returned is zero. I'm using the "Sun Java System Application Server Platform Edition 9.0_01" as my server.
>
> I've also looked into the source code, and the only place I could find source code handling the "If-Range" header was in org.apache.catalina.servlets.DefaultServlet. I think this is a potential issue but perhaps I misunderstand how the caching mechanism is supposed to work.
>
> Is this in the right place to pursue this issue or should I send this to a mailing list (and which one is most appropriate)?

This is the perfect place. Can you give me more information about your
configuration? Specially, I would like to see if you are using the
Grizzly file cache. In glassfish/domains/domain1/config/domain.xml, is
the http-file-cache global-enabled attribute set to true?

> http://forums.java.net/jive/thread.jspa?messageID=234730
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

martin_woolstenhulme
Offline
Joined: 2007-09-10

> This is the perfect place. Can you give me more
> information about your
> configuration? Specially, I would like to see if you
> are using the
> Grizzly file cache. In
> glassfish/domains/domain1/config/domain.xml, is
> the http-file-cache global-enabled attribute set to
> true?

Yes it was set to true.

>
> > > file-transmission-enabled="false"
> globally-enabled="false
>
> If you set them to false, does it makes a difference?
> I bet it will :-)

I set them to false ("off" for file-caching-enabled), but I still get the behavior described in the initial post. It responds with and HTTP 200 message, but doesn't provide the requested resource. Could it be the content of the resouce being requested is causing this behavior (a zip file or a Windows executable not html, xml, or an image)?

>
> Thanks
>
> -- Jeanfrancois
>
>
> > [Message sent by forum member
> 'martin_woolstenhulme' (martin_woolstenhulme)]
> >
> >
> http://forums.java.net/jive/thread.jspa?messageID=2347
> 30
> >
> >
> ------------------------------------------------------
> ---------------
> > To unsubscribe, e-mail:
> users-unsubscribe@glassfish.dev.java.net
> > For additional commands, e-mail:
> users-help@glassfish.dev.java.net
> >
>
> ------------------------------------------------------
> ---------------
> To unsubscribe, e-mail:
> users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail:
> users-help@glassfish.dev.java.net

Jeanfrancois Arcand

Hi,

glassfish@javadesktop.org wrote:
>> This is the perfect place. Can you give me more
>> information about your
>> configuration? Specially, I would like to see if you
>> are using the
>> Grizzly file cache. In
>> glassfish/domains/domain1/config/domain.xml, is
>> the http-file-cache global-enabled attribute set to
>> true?
>
> Yes it was set to true.
>
>>> >> file-transmission-enabled="false"
>> globally-enabled="false
>>
>> If you set them to false, does it makes a difference?
>> I bet it will :-)
>
> I set them to false ("off" for file-caching-enabled)

Just to make sure, set them to false (not off) by editing directly
domain.xml.

, but I still get the behavior described in the initial post. It
responds with and HTTP 200 message, but doesn't provide the requested
resource. Could it be the content of the resouce being requested is
causing this behavior (a zip file or a Windows executable not html, xml,
or an image)?

Is the mime-type defined in
glassfish.home/domains/domain1/config/default-web.xml?

I doubt this is the problem....Can you come with a test case I can use?

Thanks

-- Jeanfrancois

>
>> Thanks
>>
>> -- Jeanfrancois
>>
>>
>>> [Message sent by forum member
>> 'martin_woolstenhulme' (martin_woolstenhulme)]
>>>
>> http://forums.java.net/jive/thread.jspa?messageID=2347
>> 30
>>>
>> ------------------------------------------------------
>> ---------------
>>> To unsubscribe, e-mail:
>> users-unsubscribe@glassfish.dev.java.net
>>> For additional commands, e-mail:
>> users-help@glassfish.dev.java.net
>> ------------------------------------------------------
>> ---------------
>> To unsubscribe, e-mail:
>> users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail:
>> users-help@glassfish.dev.java.net
> [Message sent by forum member 'martin_woolstenhulme' (martin_woolstenhulme)]
>
> http://forums.java.net/jive/thread.jspa?messageID=234739
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

martin_woolstenhulme
Offline
Joined: 2007-09-10

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.