You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Chris Snyder <ch...@biologos.org> on 2013/07/30 19:01:31 UTC

SVG mime-type incorrect

I'm trying to serve SVG images as package resources. However, when I do so, the image files are served with a mime-type of application/xml, rather than the correct image/svg+xml. This causes strange behavior in Google Chrome - the image displays as a broken link when included in an <img/> tag, but renders fine when the image URL is opened directly. If the resource is served from the main webapp directory rather than as a package resource, the correct mime-type is sent and Chrome displays the image properly.

Delving into the code, it appears that the problem is Java's URLConnection.guessContentTypeFromStream() method, which doesn't support SVG files. I've verified this problem on both the Apple-supplied Java 1.6 and the official Oracle Java 1.7, both on MacOS X.

What would be the best way to work around this issue? I tried creating my own custom PackageResource wrapper, which had its own PackageResourceStream wrapper, but it quickly got unwieldy (as well as being a nightmare for future maintainability).

My goal is to have a subclass of Image that returns either a reference to an SVG or a PNG depending on the browser version. I first noticed the mime-type problem with my subclass, but I verified that it also exists when using the standard Image class.

Thanks in advance for your help!
-Chris Snyder
--
Chris Snyder
Web Developer, BioLogos
616.328.5208 x203
biologos.org


Re: SVG mime-type incorrect

Posted by Martin Grigorov <mg...@apache.org>.
On my
machine System.err.println(URLConnection.getFileNameMap().getContentTypeFor("file.svg"));
prints null

On Tue, Jul 30, 2013 at 7:52 PM, Martin Grigorov <mg...@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 <ch...@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 <mg...@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.
>>
>>
>

Re: SVG mime-type incorrect

Posted by Martin Grigorov <mg...@apache.org>.
On Tue, Jul 30, 2013 at 9:10 PM, Chris Snyder <ch...@biologos.org>wrote:

> 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.
>

I agree with you.
I think the code should first consult with Application#getMineType(), then
urlConnection#getContentType and finally UrlConnection#getFileNameMap.
urlConnection#getContentType uses #getHeaderName() and for
HttpUrlConnection this would matter because the http server can set
something custom.
Please file a ticket.


>
> 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 <mg...@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.snyder@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 <mg...@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.snyder@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 <mg...@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.
> >>>>
> >>>>
> >>
> >>
>
>

Re: SVG mime-type incorrect

Posted by Chris Snyder <ch...@biologos.org>.
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 <mg...@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 <ch...@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 <mg...@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.snyder@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 <mg...@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.
>>>> 
>>>> 
>> 
>> 


Re: SVG mime-type incorrect

Posted by Martin Grigorov <mg...@apache.org>.
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 <ch...@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 <mg...@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.snyder@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 <mg...@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.
> >>
> >>
>
>

Re: SVG mime-type incorrect

Posted by Chris Snyder <ch...@biologos.org>.
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 <mg...@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 <ch...@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 <mg...@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.
>> 
>> 


Re: SVG mime-type incorrect

Posted by Martin Grigorov <mg...@apache.org>.
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 <ch...@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 <mg...@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.
>
>

Re: SVG mime-type incorrect

Posted by Chris Snyder <ch...@biologos.org>.
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 <mg...@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.


Re: SVG mime-type incorrect

Posted by Martin Grigorov <mg...@apache.org>.
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.


On Tue, Jul 30, 2013 at 7:22 PM, Chris Snyder <ch...@biologos.org>wrote:

> Hi Martin,
>
> Thanks for the extremely prompt response. Unfortunately, it appears that
> Application#getMimeType isn't called for UrlResourceStream resources -
> UrlResourceStream#getData calls URLConnection#getContentType, at which
> point we've entrusted the mime-type to Java.
>
> Versions I should have included in my first email: I'm using Wicket 6.9.1,
> using the Jetty server referenced in the quickstart.
>
> Thanks,
> Chris
> --
> Chris Snyder
> Web Developer, BioLogos
> 616.328.5208 x203
> biologos.org
>
> On Jul 30, 2013, at 13:06, Martin Grigorov <mg...@apache.org> wrote:
>
> > Hi,
> >
> > You can override org.apache.wicket.Application#getMimeType
> >
> >
> > On Tue, Jul 30, 2013 at 7:01 PM, Chris Snyder <chris.snyder@biologos.org
> >wrote:
> >
> >> I'm trying to serve SVG images as package resources. However, when I do
> >> so, the image files are served with a mime-type of application/xml,
> rather
> >> than the correct image/svg+xml. This causes strange behavior in Google
> >> Chrome - the image displays as a broken link when included in an <img/>
> >> tag, but renders fine when the image URL is opened directly. If the
> >> resource is served from the main webapp directory rather than as a
> package
> >> resource, the correct mime-type is sent and Chrome displays the image
> >> properly.
> >>
> >> Delving into the code, it appears that the problem is Java's
> >> URLConnection.guessContentTypeFromStream() method, which doesn't support
> >> SVG files. I've verified this problem on both the Apple-supplied Java
> 1.6
> >> and the official Oracle Java 1.7, both on MacOS X.
> >>
> >> What would be the best way to work around this issue? I tried creating
> my
> >> own custom PackageResource wrapper, which had its own
> PackageResourceStream
> >> wrapper, but it quickly got unwieldy (as well as being a nightmare for
> >> future maintainability).
> >>
> >> My goal is to have a subclass of Image that returns either a reference
> to
> >> an SVG or a PNG depending on the browser version. I first noticed the
> >> mime-type problem with my subclass, but I verified that it also exists
> when
> >> using the standard Image class.
> >>
> >> Thanks in advance for your help!
> >> -Chris Snyder
> >> --
> >> Chris Snyder
> >> Web Developer, BioLogos
> >> 616.328.5208 x203
> >> biologos.org
> >>
> >>
>
>

Re: SVG mime-type incorrect

Posted by Chris Snyder <ch...@biologos.org>.
Hi Martin,

Thanks for the extremely prompt response. Unfortunately, it appears that Application#getMimeType isn't called for UrlResourceStream resources - UrlResourceStream#getData calls URLConnection#getContentType, at which point we've entrusted the mime-type to Java.

Versions I should have included in my first email: I'm using Wicket 6.9.1, using the Jetty server referenced in the quickstart.

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

On Jul 30, 2013, at 13:06, Martin Grigorov <mg...@apache.org> wrote:

> Hi,
> 
> You can override org.apache.wicket.Application#getMimeType
> 
> 
> On Tue, Jul 30, 2013 at 7:01 PM, Chris Snyder <ch...@biologos.org>wrote:
> 
>> I'm trying to serve SVG images as package resources. However, when I do
>> so, the image files are served with a mime-type of application/xml, rather
>> than the correct image/svg+xml. This causes strange behavior in Google
>> Chrome - the image displays as a broken link when included in an <img/>
>> tag, but renders fine when the image URL is opened directly. If the
>> resource is served from the main webapp directory rather than as a package
>> resource, the correct mime-type is sent and Chrome displays the image
>> properly.
>> 
>> Delving into the code, it appears that the problem is Java's
>> URLConnection.guessContentTypeFromStream() method, which doesn't support
>> SVG files. I've verified this problem on both the Apple-supplied Java 1.6
>> and the official Oracle Java 1.7, both on MacOS X.
>> 
>> What would be the best way to work around this issue? I tried creating my
>> own custom PackageResource wrapper, which had its own PackageResourceStream
>> wrapper, but it quickly got unwieldy (as well as being a nightmare for
>> future maintainability).
>> 
>> My goal is to have a subclass of Image that returns either a reference to
>> an SVG or a PNG depending on the browser version. I first noticed the
>> mime-type problem with my subclass, but I verified that it also exists when
>> using the standard Image class.
>> 
>> Thanks in advance for your help!
>> -Chris Snyder
>> --
>> Chris Snyder
>> Web Developer, BioLogos
>> 616.328.5208 x203
>> biologos.org
>> 
>> 


Re: SVG mime-type incorrect

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

You can override org.apache.wicket.Application#getMimeType


On Tue, Jul 30, 2013 at 7:01 PM, Chris Snyder <ch...@biologos.org>wrote:

> I'm trying to serve SVG images as package resources. However, when I do
> so, the image files are served with a mime-type of application/xml, rather
> than the correct image/svg+xml. This causes strange behavior in Google
> Chrome - the image displays as a broken link when included in an <img/>
> tag, but renders fine when the image URL is opened directly. If the
> resource is served from the main webapp directory rather than as a package
> resource, the correct mime-type is sent and Chrome displays the image
> properly.
>
> Delving into the code, it appears that the problem is Java's
> URLConnection.guessContentTypeFromStream() method, which doesn't support
> SVG files. I've verified this problem on both the Apple-supplied Java 1.6
> and the official Oracle Java 1.7, both on MacOS X.
>
> What would be the best way to work around this issue? I tried creating my
> own custom PackageResource wrapper, which had its own PackageResourceStream
> wrapper, but it quickly got unwieldy (as well as being a nightmare for
> future maintainability).
>
> My goal is to have a subclass of Image that returns either a reference to
> an SVG or a PNG depending on the browser version. I first noticed the
> mime-type problem with my subclass, but I verified that it also exists when
> using the standard Image class.
>
> Thanks in advance for your help!
> -Chris Snyder
> --
> Chris Snyder
> Web Developer, BioLogos
> 616.328.5208 x203
> biologos.org
>
>