Hi,
Apologies if this has already been covered sometime in the past...I took a
brief look through the archive, but couldn't find anything.
With the current builds of Batik, in the event that an external source is
obtained from an HTTP request that returns a non-2XX code, an IO Exception
is thrown. This means that if, for example, there was a folder of images
with a "default" image available set up via a .htaccess file, Batik would
not support it. With a similar image configured through other SVG viewers
(e.g. Chrome, Firefox, etc.) the image in the 404 file is correctly embedded
in the resulting stream.
As such, I've attached a patch which should work around this issue. In the
event an IOException is thrown by an HttpURLConnection, the ErrorStream is
returned rather than just propagating that exception.
The only downside I can see is that the "error" handler in the corresponding
web server could result something unintelligible by Batik; at which point an
error would occur further up (rather than catching it slightly earlier at
the start of reading the stream). I don't see that there would be much
difference between that and having the URL point to an incorrect (but
'valid') address.
Let me know if you've any issues / better ways to handle scenarios like
this!
Thanks,
Andrew
Index: sources/org/apache/batik/util/ParsedURLData.java
===================================================================
--- sources/org/apache/batik/util/ParsedURLData.java (revision 990078)
+++ sources/org/apache/batik/util/ParsedURLData.java (working copy)
@@ -550,7 +550,18 @@
postConnectionURL = urlC.getURL();
}
- return (stream = urlC.getInputStream());
+ try {
+ return (stream = urlC.getInputStream());
+ }
+ catch (IOException e) {
+ if (urlC instanceof HttpURLConnection) {
+ return (stream = ((HttpURLConnection) urlC).getErrorStream());
+ }
+ else {
+ throw e;
+ }
+ }
+
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]