This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: getting the JDK built-in web server to set the correct mime type


On 04/30/2013 10:55 PM, alex mitchell wrote:
Hi Per,

No problem, I figured this was probably done some time back so it might be
hard to remember why it was commented out.

I tried re-enabling it, and the first problem was that there is no
variable "context". It might be referring to hctx, but I'm not sure. The
only implementation of getMimeType I could find is in CGIServletWrapper,
which is only a stub:
   public String getMimeType (String file) { return null; }

So I'm guessing its commented out because it was not implemented yet.

That sounds right ...

This assumes that the user has a .mime.types file in one of several
possible locations as described here
http://docs.oracle.com/javase/6/docs/api/javax/activation/MimetypesFileType
Map.html, otherwise only a minimal number of mime types are recognized.


The other options that I came across when searching involved using
java.net.URLConnection.guessContentTypeFromName(path) and/or
java.net.URLConnection.guessContentTypeFromStream(resourceStream), but
these seemed to be wrong most of the time.

I'm not sure if this is the best way of doing this. Any suggestions?

I found a webpage suggesting using java.nio.file.Files.html#probeContentType
This does require Java 7.

I'll explore more later.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]