Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anyone know of a Java File servlet framework that supports HttpRanges etc

I have been attempting to find a servlet file framework that provides a bit more than just reading a file setting the appropriate headers and thats it. There are countless samples available on the net most are quite elementary and very few (almost none) support something more complex as i will describe below.

HTTP

Http provides much more rich features such as - ranges which help implement file download resumes. - cache control via etags and last modified dates.

Googling

However i cannot find anything more than a simple file servlet example. Unfortunately "Java File Download Servlet Framework" and other similar combinations, is a very overloaded form and most of the time Google returns web frameworks and not something that makes it easy to support some or all the advanced features previously mentioned.

Thinking...

Just off the top of my head the framework would provide an interface like this:

FileProvider {
   Date lastModified();
   INputStream inputStream();
   String etag();
   ...
}
  • the FileProvider takes the file path and resolves it to a real file, perhaps something from a database etc.
  • if the file has not changed (determined by reading FileProvider.lastModifier() thats it.
  • If the request is asking for a range, then the f/w would read FileProvider.inputStream() writing only the interested ranges to the HttpServletResponse.
  • The etag value would be used during the negotation phase to determine if ranges are supported etc.
  • another interface would exist to "create" the FileProvider given a path etc.

If anyone knows of a framework that separates all the nasty bits of reading headers and comparing values that would be great.

The best source i could find to get one started is

http://balusc.blogspot.com/2009/02/fileservlet-supporting-resume-and.html

but unfrotunately the sample has no provision for inserting a FileProvider and assumes that the path info from the request maps to a file on disk in some directory.

like image 397
mP. Avatar asked Nov 13 '22 21:11

mP.


1 Answers

Apache Tomcat's DefaultServlet might have most of what you're looking for. At a glance, I see ETag parsing and AcceptRange handling.

http://www.docjar.com/html/api/org/apache/catalina/servlets/DefaultServlet.java.html

like image 71
Bill Brasky Avatar answered Dec 16 '22 12:12

Bill Brasky