Marcus Crafter wrote:
>
> Have been experiencing some interesting behaviour with the source resolver
> today, and in particular the java.net.HttpURLConnection implementation.
>
> Have a look at this code:
>
> URL url = new URL("http://localhost:8080/something/somewhere/");
> URLConnection conn = url.openConnection();
> HttpURLConnection c = (HttpURLConnection) conn;
>
> System.out.println("1." + c.getInputStream());
> System.out.println("2." + c.getLastModified());
> System.out.println("3." + c.getContentType());
> System.out.println("4." + c.getResponseCode());
>
> Assuming that the URL points to a valid server, but a bogus path
> - then the
> following code raises a FileNotFoundException. However, if you move the
> call to getInputStream() to be after getResponseCode() then no
> exception is
> raised and and you'll receive a valid InputStream containing the error
> page from the server.
>
> This behaviour currently causes the SourceResolver to return server error
> pages as valid data when resolving a particular URI. From what I
> can tell,
> other than examine the content returned, there's currently no easy way to
> tell whether the SourceResolver resolved the document correctly or not.
>
> I've attached a patch that examines the return code of the
> HttpURLConnection and throws a SourceException if the code is not within
> the valid range of 200-206 as defined by the HTTP RFC.
>
> This fixes the problem, but prevents people from parsing error pages as
> Source objects (if anyone did that before?). Perhaps someone could take a
> look at the patch as maybe there's a better solution? Any ideas? If not
> let me know, and I'll apply the patch attached.
>
Interesting! The patch looks ok for me, parsing the error page is not a
thing I think we should support. So +1 for applying :)I'm only wondering if we should somehow make the status code in case of an error more "accessible" which means if the SourceException should have an extra getter for such error codes? Hmm, don't know. Carsten --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
