views:

716

answers:

2

We are getting some unexpected results randomly from some servers when trying to open an InputStream from an HttpURLConnection. It seems like those servers would accept the connection and reply with a "stay-alive" header which will keep the Socket open but doesn't allow data to be sent back to the stream.

That scenario makes an attempt for a multi-threaded crawler a little "complicated", because if some connection gets stuck, the thread running it would never return... denying the completion of it's pool which derives in the controller thinking that some threads are still working.

Is there some way to read the connection response header to identify that "stay-alive" answer and avoid trying to open the stream??

+2  A: 

Did you try setting "read time out", in addition to "connect time out"?

See http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#setReadTimeout%28int%29

palindrom
Yep... we've set both timeouts and both were ignored. We've found that this problem is a reported bug... so we're trying to workaround it. Like... if we can get that header response and isolate it... we don't open the stream. =)
Juan Manuel
This one worked out on Android.
alex
+1  A: 

I'm not sure what I'm missing here but it seems to me you simply need getHeaderField()?

wds
I'll try it and see what i get and if I can evaluate a certain answer from that! Thx.
Juan Manuel