Chris, did you actually read the link or was that a knee-jerk response? Notably the following, taken from between the first and second boxed pieces of code on that page:
"The openStream() method is actually just a shortcut for openConnection().getInputStream()." ... plus the source of openStream() to prove it. So, yes, you *are* using a URLConnection internally. And... correct, you're not setting any timeouts in your code. But you want to. That page provides code further down that allows you to set such a timeout. - Peter On 12 February 2010 12:24, Chris Mannion <chris.mann...@icasework.com> wrote: > Thanks Peter but we're not using a URLConnection, nor are we > explicitly setting any timeouts, as you can see from the code. > > On 12 February 2010 12:06, Peter Crowther <peter.crowt...@melandra.com> wrote: >> A swift Google for: >> java url openStream timeout >> reveals: >> http://stuffthathappens.com/blog/2007/09/10/urlopenstream-might-leave-you-hanging/ >> as its first hit. >> >> In essence: the timeout is controlled by setTimeout on UrlConnection. >> >> On 12 February 2010 11:59, Chris Mannion <chris.mann...@icasework.com> wrote: >>> Hi all >>> >>> Hoping someone can shed some light on a little puzzle I have. This >>> may be more a Java programming problem than a Tomcat problem so >>> apologies if that is the case but it's specific to a system running on >>> Tomcat so I'm asking here too. One of our servlets is opening a URL >>> connection to hit an external URL, the external URL can sometimes take >>> a while to respond and when that happens the URL connection throws a >>> socket timeout exception (see the stack trace below). What I can't >>> work out is what determines how long the connection waits before it >>> times-out, we don't set anything explicitly in our code and it doesn't >>> seem to be related to the servlet timeout in the connector, does >>> anyone know what determines the timeout length and how it can be >>> changed? The code is simply - >>> >>> public void outputUrl(OutputStream p_out, String p_url) { >>> try { >>> URL t_url = new URL(p_url); >>> InputStream t_inputStream = t_url.openStream(); >>> // Read from the input stream, and write to the output stream >>> byte[] l_buffer = new byte[10]; // buffer holding bytes to >>> be transferred >>> int l_nbytes = 0; // Number of bytes read >>> while ((l_nbytes = t_inputStream.read(l_buffer)) != -1) >>> p_out.write(l_buffer,0,l_nbytes); >>> t_inputStream.close(); >>> } >>> catch (Exception e) >>> { >>> nsglog.error(String.valueOf(e), e); >>> } >>> } >>> >>> The error trace is - >>> >>> java.net.SocketTimeoutException: Read timed out >>> at java.net.SocketInputStream.socketRead0(Native Method) >>> at java.net.SocketInputStream.read(SocketInputStream.java:129) >>> at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) >>> at java.io.BufferedInputStream.read1(BufferedInputStream.java:256) >>> at java.io.BufferedInputStream.read(BufferedInputStream.java:313) >>> at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:659) >>> at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:604) >>> at >>> sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:961) >>> at java.net.URL.openStream(URL.java:1007) >>> at ep.ext.outputUrl(ext.java:446) >>> >>> So it's the attempt to open the input stream on the URL that is timing >>> out, what governs that timeout? >>> >>> -- >>> Chris Mannion >>> iCasework and LocalAlert implementation team >>> 0208 144 4416 >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >>> For additional commands, e-mail: users-h...@tomcat.apache.org >>> >>> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> > > > > -- > Chris Mannion > iCasework and LocalAlert implementation team > 0208 144 4416 > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org