Good catch - thanks. Though it turns out that the mailcap stuff is all a red 
herring - they're just a stub for some code that somebody (probably in 1996 or 
thereabouts) thought they'd implement someday:
> // For backward compatibility -- mailcap format files
> // This is not currently used, but may in the future when we add ability
> // to read BOTH the properties format and the mailcap format.

Here's where the actual content-type loading takes place:
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/sun/net/www/MimeTable.java#229

To get this working, I copied the content-types.properties file from the Java 
lib directory to in the package next to the Wicket Start class, added an entry 
for SVG (the stock file is quite sparse), and added the following line in 
Start#main:
> System.setProperty("content.types.user.table", 
> Start.class.getResource("content-types.properties").getPath());

After doing that, it works properly - the correct mime-type is served, and 
Chrome displays the image. This is hardly a good solution for a production 
environment, but it will suffice for now.

Given how much of a mess that Java code is, it seems to me that Wicket's 
UrlResourceStream#getData method should be modified to not call 
URLConnection#getContentType at all. The behavior for when getContentType 
returns null - ask the Application [if it exists], or consult 
URLConnection#getFileNameMap - looks to be better for all cases.

Thanks so much for your help. I'm just getting into Wicket programming, and am 
very impressed with the helpfulness of the community.

Thanks,
Chris
--
Chris Snyder
Web Developer, BioLogos
616.328.5208 x203
biologos.org

On Jul 30, 2013, at 14:23, Martin Grigorov <mgrigo...@apache.org> wrote:

> You are right.
> It tries with getHeaderName(String) which looks in MimeTable and falls back
> to by stream.
> I think you need to set the type in your mailcap file.
> 
> 
> On Tue, Jul 30, 2013 at 8:16 PM, Chris Snyder 
> <chris.sny...@biologos.org>wrote:
> 
>> Except that URLConnection#getContentType doesn't even use MimeTable:
>> 
>> http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/sun/net/www/URLConnection.java?av=f#147
>> 
>> URLConnection#guessContentTypeFromStream is what it's using:
>> 
>> http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/net/URLConnection.java#URLConnection.guessContentTypeFromStream%28java.io.InputStream%29
>> Ugh - what a mess. That seems like a very arbitrary set of filetypes to
>> test for (FlashPix?). It sees that the SVG file starts with <?xml…, so it
>> returns application/xml - not wrong, per se - but not accurate enough.
>> 
>>> On my
>>> machine
>> System.err.println(URLConnection.getFileNameMap().getContentTypeFor("file.svg"));
>>> prints null
>> Same here. However, the following returns "application/xml" (test.svg must
>> be an SVG file, of course):
>> 
>> System.err.println(URLConnection.guessContentTypeFromStream(getClass().getResourceAsStream("test.svg")));
>> 
>> Thanks,
>> Chris
>> --
>> Chris Snyder
>> Web Developer, BioLogos
>> 616.328.5208 x203
>> biologos.org
>> 
>> On Jul 30, 2013, at 13:52, Martin Grigorov <mgrigo...@apache.org> wrote:
>> 
>>> This is nasty indeed!
>>> 
>>> According to
>>> 
>> http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/sun/net/www/MimeTable.java#MimeTable
>>> the
>>> mime types are loaded from mailcap files.
>>> See "man update-mime"
>>> 
>>> 
>>> On Tue, Jul 30, 2013 at 7:40 PM, Chris Snyder <chris.sny...@biologos.org
>>> wrote:
>>> 
>>>> However, just above that (line 122) it gets the contentType from the
>>>> URLConnection, which returns "application/xml". Since
>>>> streamData.contentType is not null, it never gets to line 126.
>>>> 
>>>> Thanks so much for your help!
>>>> 
>>>> -Chris
>>>> --
>>>> Chris Snyder
>>>> Web Developer, BioLogos
>>>> 616.328.5208 x203
>>>> biologos.org
>>>> 
>>>> On Jul 30, 2013, at 13:30, Martin Grigorov <mgrigo...@apache.org>
>> wrote:
>>>> 
>>>>> Hi,
>>>>> 
>>>>> According to
>>>>> 
>>>> 
>> https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/core/util/resource/UrlResourceStream.java?source=cc#L126
>>>>> if
>>>>> theere is an application then it should be used before falling back.
>>>> 
>>>> 
>> 
>> 

Reply via email to