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


Hi Per,

It seems that in my case absPath is a gnu.text.URLPath, so I used your
original suggested code which tests for FilePath, but with an additional
'else' condition which tests for 'absPath instanceof URLPath'. To handle
that case, I added toNPath in URLPath using Paths.get(absPath.toUri()) as
you had suggested. I'm not sure what additional error checking is needed,
if any. See the attached patch.

This seems to work for me (tested on Windows 7 with Java 7, and MacOS
10.6.8 with Java 6). Note that for Java 6, it requires a .mime.types file
for javax.activation.MimetypesFileTypeMap to use for lookup.

Alex

On 13-05-03 1:19 AM, "Per Bothner" <per@bothner.com> wrote:

>On 05/02/2013 01:59 AM, alex mitchell wrote:
>> Hi Per,
>>
>> Thanks. However, I tried the patch, and it only sets the mime type for
>> text/html. For other file types, such as .js or .css, the mime type
>>still
>> isn't set. I think what is happening is that absPath is an instance of
>> URLPath, not FilePath, so the code:
>>
>> if (absPath instanceof FilePath) {
>>    contentType = Files.probeContentType
>>      (((FilePath) absPath).toNPath());
>> }
>>
>> is never entered.
>
>Presumably absPath is a file: URL, so it should be easy to convert
>it to a java.nio.file.Path.  We just need to find a clean way to do it.
>Possibly replace 'absPath instanceof FilePath' by
>   "file".equals(absPath.getScheme())
>The cast of courseabsPath.toURI would have to be more complex.  Perhaps:
>   Paths.get(absPath.toUri())
>though maybe with some extra null-checks or try/catches.
>
>> Then the subsequent call to URLConnection.guessContentTypeFromName(path)
>> seems to recognize very few mime types, returning null for almost
>> everything. I found that javax.activation.MimetypesFileTypeMap seems to
>> work better, since it allows for additional mime types to be specified,
>> but there may be a good reason for not using this.
>
>No reason I can think of.
>
>-- 
>	--Per Bothner
>per@bothner.com   http://per.bothner.com/

Attachment: mimetype.patch
Description: Binary data


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