https://issues.apache.org/bugzilla/show_bug.cgi?id=51197

--- Comment #7 from Christopher Schultz <ch...@christopherschultz.net> 
2012-02-21 16:48:05 UTC ---
Konstantin,

(In reply to comment #5)
> The
> URLConnection used to implement getUrl() cannot read content if response code
> is >= 400.If I remove status code check in TomcatBaseTest#getUrl() to always
> read response text regardless of status code, it just fails with an
> IOException:

You have to use URLConnection.getErrorStream if the response code is
"problematic". I have this code in a class that fetches data from an HTTP
server:

        int responseCode = conn.getResponseCode();

        boolean error = 5 == responseCode / 100
            || 4 == responseCode / 100;

        if(error)
            in = new BufferedInputStream(conn.getErrorStream());
        else
            in = new BufferedInputStream(conn.getInputStream());

Then I just use "in" as I please.

> Caused by: java.io.IOException: Server returned HTTP response code: 400 for
> URL: http://localhost:3596/asyncErrorServlet
>     at
> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
>     at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
>     at
> org.apache.catalina.startup.TomcatBaseTest.getUrl(TomcatBaseTest.java:232)
> ]]]

Weird that it's throwing an exception from getResponseCode. What JRE are you
using?

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to