2012/3/23 Serdyn du Toit <dutoi...@gmail.com>:
> Hi,
>
> Using Tomcat 6.0.35 I got the server up and running and could retrieve
> webpages from my application perfectly - using the browser.  Now I've
> written some client code of my own in Java and for one or other reason it
> doesn't want to retrieve everything - it only returns a partial response
> and then hangs.  Multiple attempts at returning the webpage returns the
> same partial response - in other words its still a partial response but its
> the exact same length as the partial responses returned by the other
> attempts.
>
> I had the same issue in Jetty so I'm not sure what it could be, but maybe
> there is some setting on my machine (Windows Vista) that's preventing any
> non-browser connection with the webservers to work 100%?
>
> The client code was first in Jersey (jersey.java.net), then written in
> plain Java, and then using Apache HttpComponents (hc.apache.org).  All
> versions of client code hanged.

Take a thread dump to see where you code spends its time when you
think it is hanging. Is is better to take several (3) dumps with some
time interval.

See FAQ
http://wiki.apache.org/tomcat/FAQ/Troubleshooting_and_Diagnostics
-> "How To: Capture a thread dump"

>  The Java code (though its 100%) is as
> follows:
>
> String jsonResponse = "";
> {
> //
> http://docs.oracle.com/javase/tutorial/networking/urls/readingWriting.html
> URLConnection urlConnection = new URL(uri).openConnection();
>        BufferedReader br = new BufferedReader(new
> InputStreamReader(urlConnection.getInputStream()));

Using InputStreamReader(stream) constructor is wrong in 90% of cases.

You should always pass an encoding as the second argument.
For JSON it is usually "UTF-8".

>        String inputLine = null;
>        while ((inputLine = br.readLine()) != null)
>    jsonResponse += inputLine;

The above is a wrong way to concatenate strings. Do not do it in a
loop. Use a StringBuilder.

If you just need the text (not the lines), I would recommend to use
reader.read(char[])

>        br.close();
> }
>
> One clue - when I changed the connector's socketBuffer (
> http://tomcat.apache.org/tomcat-5.5-doc/config/http.html) the length of the
> partial response varied.  But it still didn't return the full response.
>  And the default setting worked for the browser...so no idea what could be
> wrong...
>
> Probably not a Tomcat issue - but any suggestions on what could be causing
> this would be appreciated.
>

Best regards,
Konstantin Kolinko

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

Reply via email to