HttpURLConnection timeout

How do I set the timeout for an HttpURLConnection. What happens if there is no reponse from the server I am connecting to?. Thank you for any response.

Details about the problem: This happens once in a while.
I am using iPlanet API on WebSphere to get the portal session from remote portal server. This API has static synchronized methods, the thread dump shows it is hanging at these methods when this problem occurs. This API uses HttpURLConnection to portal servers.
Our understanding is, the failure of the first thread causes the
subsequent threads to build up and make the web server hang. By restarting the WebSphere, this problem is solved. We have 2 app servers runs in cloned env with 1 web server. Remote OSE acts as load balancer.
The question is : how to make the portal server connection time based so that if it did not get the response back in stipulated time, stop that process and allow next thread to perform.
Thank you!.

Similar Messages

  • How to set HttpURLConnection timeout while reading a stream?

    I want it got time out if the connection if lose while i read a stream from URL
    try {
         int timeout = 700;
         HttpURLConnection connection = (HttpURLConnection) downloadURl.openConnection();
         connection.setConnectTimeout(timeout);
         connection.setRequestProperty("Range","bytes=" + downloaded + "-");
         connection.connect();
         if (connection.getResponseCode() / 100 != 2) {
              error();
         int contentLength = connection.getContentLength();
         if (contentLength < 1) {
              error();
         if (status == DOWNLOADING){
              if (size == -1) {
                   size = contentLength;
              file = new RandomAccessFile(saveTmpName+".tmp", "rw");
              file.seek(downloaded);
         byte buffer[];
         stream = connection.getInputStream();
    connection.setReadTimeout(timeout);
         while (status == DOWNLOADING) { 
              if (size - downloaded > MAX_BUFFER_SIZE) {
                   buffer = new byte[MAX_BUFFER_SIZE];
              } else {
                   buffer = new byte[(int)(size - downloaded)];
              int read = stream.read(buffer); // how to set timeout while it is reading stream
              if (read <= 0)
                   break;
              file.write(buffer, 0, read);
              downloaded += read;
         if (status == DOWNLOADING) {
              status = COMPLETE;
    } catch (SocketTimeoutException  e) {
         error();
    } catch (IllegalArgumentException e) {
         error();
    } catch (Exception e) {
         error();
    } finally {
         if (file != null) {
              try {
                   file.close();
              } catch (Exception e) {}
         if (stream != null) {
              try {
                   stream.close();
              } catch (Exception e) {}
    }I try to set "setReadTimeout()" but is still not through timeout Exception

    ejp wrote:
    Because, there's no FTP client command that allows to do such thing.Socket.setSoTimeout().I agree with you on this one but the OP is talking about the FTPClient API from Apache.
    To the OP,
    BTW, I have reread the Javadoc about the [*API*|http://commons.apache.org/net/api/org/apache/commons/net/ftp/FTPClient.html] : indeed, there's no setTimeout method, but there is a setDataTimeout method : +Sets the timeout in milliseconds to use when reading from the data connection+ .

  • Setting Timeout  in URLConnection/HttpURLConnection

    Hi all,
    I am trying to open a connection a website using the java.net.HttpURLConnection.
    Please tell me what is the default timeout (how much time it will wait for getting reply ) and how we can change the
    default value. Please help me.
    Thanks in advance.

    This seems to be what you are looking for.
    [http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#setReadTimeout%28int%29|http://java.sun.com/j2se/1.5.0/docs/api/java/net/URLConnection.html#setReadTimeout%28int%29]

  • Timeout using HttpUrlConnection

    Dear all,
    today I found out that my software has a problem with the standard timeout using the HttpUrlConnection. I have to connect to a server and have to read a file with more than 1400 Byte. After 1460 Byte it seems that the connection is closed. I downloaded some pieces of code (http://groups.google.de/groups?hl=de&lr=&selm=b7aab076.0401230914.6c2c678f%40posting.google.com&rnum=1) and added it to my software (creating new TimeoutHandler, ...). But I still get this timeout - or it seems like it is a timeout.
    Any ideas??
    Thx,
    Sabine

    today I found out that my software has a problem with
    the standard timeout using the HttpUrlConnection.What timeout? I don't believe there is one with this class. Maybe the server side is closing the connection - and if that's the case, it's not going to matter what you do on the client end.

  • SSL timeout with HttpURLConnection

    I'm using an HttpURLConnection to connect to a URL (in my case, an https URL). The readtimeout on the HttpURLConnection has not been set, so it's the default of no timeout. The HttpURLConnection is able to connect immediately, but getting a response back can take some time (the URL points to a servlet that does some work that can take a little while). When it's less than 10 minutes, this works fine. When it takes more than 10 minutes, HttpURLConnection.getContentType() throws a SocketException:
    java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:168)
    at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:284)
    at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:319)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:720)
    at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:677)
    at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
    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:606)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:554)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:571)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:928)
    at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:1850)
    at java.net.URLConnection.getContentType(URLConnection.java:479)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getContentType(HttpsURLConnectionImpl.java:382)
    It appears that there is some sort of underlying SSL-related timeout that, in this case, is set to 10 minutes. Does anyone know what might be causing this and how I can change it programmatically?
    Thanks,
    vlb514

    The server is resetting the connection.

  • Configuring a timeout in HttpURLConnection

              Greetings,
              I am using HttpURLConnection class to do posts and then reading the response
              by opening an InputStream on the same connection.
              Is there some way of putting in a Timeout, such that, if I dont receive any response
              within that period, i cd disconnect or return.
              Thanks in advance...
              Regards
              Vinay S
              

    Hi,
              No, you should be good to go. The HttpURLConnection.setTimeout(int) is all you need to
              call. It does essentially what the code at the url you sent me does. It sets the timeout
              value on the socket. You can drop the classes from logicamente.
              Bill
              Vinay S wrote:
              > Hey William,
              >
              > I am using wls 6.1sp2. Now, if i obtain the patch from support, would i still
              > need to use the classes from
              > http://www.logicamente.com/sockets.html, or there is a new way, using weblogic
              > patch?
              >
              > Regards
              > Vinay
              >
              > William Kemp <[email protected]> wrote:
              > >Hi,
              > >
              > >This feature was added in 6.1, but needs a patch to work correctly. The
              > >change request
              > >is CR055987 and has a patch for 6.1sp2. If I remember correctly, when
              > >the connection
              > >times out, an exception is thrown so that you can recover accordingly.
              > >Support can give
              > >you the patch.
              > >
              > >As an aside, I find it amazing that this was never an option to HttpURLConnection
              > >until
              > >1.4. We just added it because it seemed obvious. Maybe not to everybody.
              > >;-)
              > >
              > >Bill
              > >
              > >Vinay S wrote:
              > >
              > >> Thanks Dimitri.
              > >>
              > >> I am using and Sun JDK 1.3.1 (wls 6.1) and i tried the first option.
              > >There seems
              > >> to be a problem.
              > >> If the connection times out, no exception is thrown, it just waits
              > >there, it doesnt
              > >> even exit. Is there any workaround for this? I need to take some actions
              > >if the
              > >> connection timesout, but there seems to be no intimation.
              > >>
              > >> any suggetions?
              > >>
              > >> Regards
              > >> Vinay
              > >>
              > >> "Dimitri I. Rakitine" <[email protected]> wrote:
              > >> >For some strange reason this feature was not supported until 1.4.
              > >> >
              > >> >If you use Sun's JDK, this hack works:
              > >> >
              > >> >http://www.logicamente.com/sockets.html
              > >> >
              > >> >(or you can use a different HTTP client - http://www.innovation.ch/java/HTTPClient/
              > >> >for example).
              > >> >
              > >> >Vinay S <[email protected]> wrote:
              > >> >
              > >> >> Greetings,
              > >> >
              > >> >> I am using HttpURLConnection class to do posts and then reading
              > >the
              > >> >response
              > >> >> by opening an InputStream on the same connection.
              > >> >> Is there some way of putting in a Timeout, such that, if I dont
              > >receive
              > >> >any response
              > >> >> within that period, i cd disconnect or return.
              > >> >
              > >> >> Thanks in advance...
              > >> >
              > >> >> Regards
              > >> >> Vinay S
              > >> >
              > >> >--
              > >> >Dimitri
              > >
              

  • EJB / Timeout / HttpUrlConnection

    I have an EJB that needs to talk to an outside vendor using http.
    Is there a way I can specify a timeout and thus if the vendor http port is down,
    the bean doesn't try forever to connect.
    I saw a similar post in this newsgroup and a proposed solution but that works
    only for https.
    I was hoping to find either 1) a property somewhere in weblogic to control the
    timeout parameter. This call is in a bean method by itself.
    2) A timeout parameter that could be specified while connecting to the external
    port.
    We are using WLS 6.1/JDK 1.3.1.
    Here is a code snippet...
    URL myURL = new URL (....)
    HttpURLConnection myConn = myURL.getOpenConnection();
    myURL.getOutputStream()

    1.4 finally supports this. Using 1.3 you have several choices to add
    read timeout:
    use HTTPClient: http://www.innovation.ch/java/HTTPClient/
    if you use Sun's JVM this hack works: http://www.logicamente.com/sockets.html
    2) Until 1.4 there is no way to specify socket connect timeout.
    Ashish <[email protected]> wrote:
    I have an EJB that needs to talk to an outside vendor using http.
    Is there a way I can specify a timeout and thus if the vendor http port is down,
    the bean doesn't try forever to connect.
    I saw a similar post in this newsgroup and a proposed solution but that works
    only for https.
    I was hoping to find either 1) a property somewhere in weblogic to control the
    timeout parameter. This call is in a bean method by itself.
    2) A timeout parameter that could be specified while connecting to the external
    port.
    We are using WLS 6.1/JDK 1.3.1.
    Here is a code snippet...
    URL myURL = new URL (....)
    HttpURLConnection myConn = myURL.getOpenConnection();
    myURL.getOutputStream()--
    Dimitri

  • HttpURLConnection setTimeout won't timeout for wls7sp6

    Hi,
              I am runing wls7.0 sp6. In the following code the timeout setting has no effect at all.
              URL url = new URL(host);
              HttpURLConnection conn = (HttpURLConnection) url.openConnection();
              conn.setDoOutput(true);
              conn.setDoInput(true);
              conn.setUseCaches(false);
              conn.setReadTimeout(5000); //conn.setTimeout(5000) is same
              conn.setRequestMethod("POST");
              String data = "name=test&value=test2";
              long start = System.currentTimeMillis();
              conn.connect();
              long c = System.currentTimeMillis();
              System.out.println("conn end: " + (c-start));
              BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
              writer.write(data);
              writer.close();
              long w = System.currentTimeMillis();
              System.out.println("writer: " + (w-c));
              int returnCode = conn.getResponseCode();
              long r = System.currentTimeMillis();
              System.out.println("end: " + (r-w));
              conn.disconnect();
              The output is:
              conn end: 15
              writer: 0
              end: 28110
              It took more than 28 sec to complete even though I set to be 5 sec. I upgrade from sp1 for this feature only, but it still won't work. HELP please.

    Did you reslove this problem as I am having the same problem

  • HttpURLConnection response timeout?

    All,
    I'm writing a batch-mode application that sends requests via HTTP(s) to gather information in a loop. The service provider in this case is relatively flakey, and will sometimes hold the connection open and not respond, at times for more than a half hour (effectively dead). I need to disconnect and retry the request if I detect the connection has been held open with no data passed for some amount of time. Does anyone have a solution for this?
    Thanks,
    ~ Paul

    Have a look at apacje's http-client. It has a timeout setting for HTTP requests.

  • HTTP(S) Timeout while invoking WebService over HTTPS.

    Hello,
    I have some stress with my webservice client implementation.
    I do the following (I can post source code if needed):
    - As usual:
    System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
    Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
    - Install my TrustManager
    - Install my DefaultHostnameVerifier
    - Register a custom type
    - Make a javax.xml.rpc.Call to access a webservice
    My observations:
    The code works well when using an HTTP URL, just changing the target URL to HTTPS causes the problem.
    The HTTPS web service (on server) works well seeing a HTTPS client using the weblogic SSL implementation, or an AXIS client can easily connect.
    When I use a simple and direct "Open HttpsURLConnection on URL("https://xxx.service?WSDL"); print-out-all-that's-coming-in", it works well. I think my SSL access is made correctly.
    The client does not complain about not-installed SSL things, all certificates are accepted, etc. No problem at this part.
    System.setProperty("javax.net.debug", "all") is set, but i dont see anything of interrest.
    I use the packages contained in 'java_xml_pack-summer-02_01' of SUN (jaxm-1.1_01, jaxp-1.2_01,jaxr-1.0_02 etc and the jsse 1.0.3).
    The server is weblogic 7.
    Calling
    call.setTargetEndpointAddress("http://arakis:7001/traces_ws/searchCertificate");
    works well while
    call.setTargetEndpointAddress("https://arakis:7002/traces_ws/searchCertificate");
    causes (after 2 minutes):
    HTTP transport error: java.net.SocketException: Unexpected end of file from server
    at com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpClientTransport.java:189)
    at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:73)
    at com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:54)
    at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:279)
    at SSLSOAPClient.main(SSLSOAPClient.java:264)
    CAUSE:
    java.net.SocketException: Unexpected end of file from server
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:699)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:604)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:697)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:604)
    at com.sun.xml.rpc.client.http.handler.HttpURLConnection.getInputStream(HttpURLConnection.java:543)
    at com.sun.xml.rpc.client.http.handler.HttpURLConnection.getResponseCode(HttpURLConnection.java:920)
    at com.sun.xml.rpc.client.http.HttpClientTransport.invoke(HttpClientTransport.java:123)
    at com.sun.xml.rpc.client.StreamingSender._send(StreamingSender.java:73)
    at com.sun.xml.rpc.client.dii.CallInvokerImpl.doInvoke(CallInvokerImpl.java:54)
    at com.sun.xml.rpc.client.dii.BasicCall.invoke(BasicCall.java:279)
    at SSLSOAPClient.main(SSLSOAPClient.java:264)
    Exception in thread "main"
    What I note is that the call is using a HttpURLConnection object and NOT a HttpsURLConnection object (so problems are 'normal' i guess), but I dont have any clue what I have to do to instruct the client to use HTTPS other than specifying HTTPS in the target.
    Hope someone has an idea
    Tasha

    Hello,
    The default timeout in Axis is 60 seconds, you can change it by your client code, and you can still keep the session to call many times
    ((org.apache.axis.client.Stub)service).setMaintainSession(true); //keep session
    ((org.apache.axis.client.Stub)service).setTimeout(60*1000*30); //half hour
    Lixin

  • Help needed to start HTTP Protocol with timeout

    I am looking for information to point me in the right direction. I would like to create a class that would implement the HTTP protocol and would allow the user to specify a timeout if unable to connect to the server. I have used the URL and HttpURLConnection classes before, but have not used any of the other classes in the java.net package. I am just trying to create an app that will download a file from a specified URL. Something that I could use in the future and something to get more programming experience using the java.net package.
    Could you tell me:
    1) Which classes I would need to use to help implement a timeout
    2) Where I can find an example or other information on how to implement the HTTP protocol with the class from question 1 above.
    TIA for any information

    That would definately reduce the coding time but would
    do little to help with my understanding of classes in
    the java.net package or to gather a better
    understanding of the HTTP protocol. :-)
    That said, I am currently downloading the 1.5 beta to
    see what they have done.If it's just an academic thing to re-invent the wheel (code) that deals with the HTTP protocol, then go right ahead (ok, you don't need my permission).

  • Problem using HttpURLConnection

    Hi
    I am using HttpURLConnection,to download the contents from the URL,in my application.
    When only a limitted no of threads are started then it is working fine and the stuffs are getting downloaded into a file as per my requirement However if if sponning a large number of thread or if the http server is slow then
    instead of downloading the contents slowly...the inputsteam is showing eof and the downloading is completed without actual completino.Hence i am failing to dowload all the contents{color:#008000}.(The application requires to start around 100 threads and download the contents of all the urls into a single file){color}
    Following code has been used :
    {color:#3366ff}+url = new URL(httpUrl);+
    conn = (HttpURLConnection) url.openConnection();
    conn.setRequestMethod("GET");
    conn.setAllowUserInteraction(false);
    conn.setDoInput(true);
    conn.setDoOutput(true);
    conn.setUseCaches(false);
    conn.connect();
    appendToTempFile("");
    appendToTempFile("");
    appendToTempFile("Downloading " httpUrl);+
    in = conn.getInputStream();
    BufferedReader reader =BufferedReader(new InputStreamReader(in));
    String text;
    +while ((text = reader.readLine()) != null) {+
    if (!text.startsWith(" "))
    appendToTempFile(text);
    +}+
    +}+
    conn.disconnect();
    *{color:#000000}Please suggest me some solution.{color}*
    {color}

    1.
    Are you writing to the file with all threads at the same time? Then this could be a problem. My approach would be a consumer/producer pattern, where the download threads are the producers. They download the data and store it at a central place. Another thread, the consumer, fetches the data from this central place and writes it the file. This way you only have one thread, which is working with the file and you don't get problems like one thread is overwriting the data of another thread.
    2.
    If you start many download threads, there yould be limitations, which could result in timeouts or something like that. Some servers only allow a defined number of connections from one IP. Same goes for your browser. Firefox for example can be configured to open only a specified number of connections to one server. There are some os settings, which could be limitating, too. So you should try to not use too many threads. You could use a thread pool, for example.

  • Connection timeout when using iPlanet web-server uses Weblogic 6.1 proxy server to proxy requests to an HTTP server

    Hi all,
    My configuration is as follows: I have an iPlanet web-server that uses a WebLogic
    6.1 (sp1) server to proxy requests to another HTTP server. The HTTP request runs
    for 120 seconds. This causes Weblogic to timeout after a while. The error I get
    is as follows:
    <Aug 25, 2003 3:37:09 PM GMT+00:00> <Warning> <HttpClient> <Couldn't open connection
    java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:320)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:133)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:120)
    at java.net.Socket.<init>(Socket.java:273)
    at java.net.Socket.<init>(Socket.java:127)
    at weblogic.net.http.HttpClient.openServer(HttpClient.java:194)
    at weblogic.net.http.HttpClient.openServer(HttpClient.java:254)
    at weblogic.net.http.HttpClient.<init>(HttpClient.java:117)
    at weblogic.net.http.HttpClient.New(HttpClient.java:149)
    at weblogic.net.http.HttpURLConnection.connect(HttpURLConnection.java:109)
    at com.db.gmr.dcm.DebtIssueServlet.getVectorFromConnection(DebtIssueServle
    t.java:285)
    at com.db.gmr.dcm.IssuesUSThread.run(IssuesUSThread.java:29)
    >
    I get the same error when I added the following plug-in configuration parameters
    (in obj.conf):
    ConnectTimeoutSecs="170" ConnectRetrySecs="170".
    What do I need to do to extend this timeout? Any help you can provide will be
    greatly appreciated..
    Thanks
    Manish

    Hi all,
    My configuration is as follows: I have an iPlanet web-server that uses a WebLogic
    6.1 (sp1) server to proxy requests to another HTTP server. The HTTP request runs
    for 120 seconds. This causes Weblogic to timeout after a while. The error I get
    is as follows:
    <Aug 25, 2003 3:37:09 PM GMT+00:00> <Warning> <HttpClient> <Couldn't open connection
    java.net.ConnectException: Connection timed out
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:320)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:133)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:120)
    at java.net.Socket.<init>(Socket.java:273)
    at java.net.Socket.<init>(Socket.java:127)
    at weblogic.net.http.HttpClient.openServer(HttpClient.java:194)
    at weblogic.net.http.HttpClient.openServer(HttpClient.java:254)
    at weblogic.net.http.HttpClient.<init>(HttpClient.java:117)
    at weblogic.net.http.HttpClient.New(HttpClient.java:149)
    at weblogic.net.http.HttpURLConnection.connect(HttpURLConnection.java:109)
    at com.db.gmr.dcm.DebtIssueServlet.getVectorFromConnection(DebtIssueServle
    t.java:285)
    at com.db.gmr.dcm.IssuesUSThread.run(IssuesUSThread.java:29)
    >
    I get the same error when I added the following plug-in configuration parameters
    (in obj.conf):
    ConnectTimeoutSecs="170" ConnectRetrySecs="170".
    What do I need to do to extend this timeout? Any help you can provide will be
    greatly appreciated..
    Thanks
    Manish

  • Problem when using the Http TimeOut system parameter in JDK 1.4

    Hi,
    The JDK 1.4 URLConnection class seems to be caching the timeout values in JDK 1.4. Hence this result in a inflexibility of setting the timeout value once for the entire functioning of the JVM. The sample code is below
    public class TestUrlConnection {
         * main method
         * @param args
         public static void main(String[] args) throws Exception {
              try {
                   System.setProperty("sun.net.client.defaultReadTimeout","1000");
                   System.out.println("Testing Connection Timeout Parse I");
                   URL url =
                        new URL("http://localhost:9080/StrutsApplicationWeb/timeOutTest.do");
                   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                   System.out.println("Conn Type:" + conn.getContentType());
                   System.out.println("Conn Encoding:" + conn.getContentEncoding());
                   System.out.println("Conn Resp Code:" + conn.getResponseCode());
              } catch (SocketTimeoutException se) {
                   System.out.println("Timeout parse I");
              try {
                   System.setProperty("sun.net.client.defaultReadTimeout","25000");
                   System.out.println("Testing Connection Timeout Parse II");
                   URL url =
                        new URL("http://localhost:9080/StrutsApplicationWeb/timeOutTest.do");
                   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                   System.out.println("Conn Type:" + conn.getContentType());
                   System.out.println("Conn Encoding:" + conn.getContentEncoding());
                   System.out.println("Conn Resp Code:" + conn.getResponseCode());
              } catch (SocketTimeoutException se) {
                   System.out.println("Timeout parse II");
    The server is a URL that produces an delay of 20 secs. Hence as per above code the first parse should fail but the second one should succeed. As URLConnection is caching the timeout value, the code is not functioning properly. Do you guys think, it is ok for URLConnection to cache timeout values???

    that is odd. I thought I saw the source to
    HttpURLConnection once, and the default timeout is
    hardcoded in the code, so there was no way of setting
    the time out. maybe right, i saw that setting a system property the second time dint seem to alter the value, but made the mistake of assuming that the connection picked up the timeout value first time from the system property the first time it was defined
    >
    1.5 changes this.setConnectionTimeout(int)

  • DocumentBuilder timeout - parse(url)

    Is there anyway to configure a timeout on parsing from a url with DocumentBuilder?
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
    Document document = docBuilder.parse(url);I can't seem to find a reference anywhere

    tony_murphy wrote:
    Is there anyway to configure a timeout on parsing from a url with DocumentBuilder?
    I can't seem to find a reference anywhereI think it is not the job of DocumentBuilder, DocumentBuilder is capable of parsing number of sources for building Document.
    Try other way with parsing InputStream. Check it out below:
    import java.io.*;
    import java.net.*;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    try
         URL url = new URL (strURL);     // Getting URL to invoke
         HttpURLConnection urlCon = (HttpURLConnection) url.openConnection ();     // Opening connection with the URL specified
         urlCon.setReadTimeout (1000);     // Set Read Time out in milliseconds, Setting 1 second as read timeout
         urlCon.connect ();     //Connecting
         InputStream iStream = urlCon.getInputStream ();     //Opening InputStream to Read
         DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();     //Building Document Builder Factory
         DocumentBuilder builder = factory.newDocumentBuilder();     // Building Document Builder
         doc = builder.parse(iStream);     // Parsing InputStream
    } catch (Exception ex) {
         // TODO: Exception Handling
    Note: Perform proper Exception Handling.
    Thanks,
    Tejas

Maybe you are looking for

  • How to obtain most popular cities from my users table

    Hi. I've got a 'users' table: USER_ID --- CITY_ID 1 ---- 32 2 ---- 20 3----- 32 4 ---- 32 5 ----- 17 I would like to obtain the most popular cities from this table, and the number of occurrences. Is this possible to make it easy with an SQL statement

  • Error 01006 with prepared statement

    I have the 1006 error with the statement: prepstmt = conn.prepareStatement select col from table where col = '?' The parameter is set with setString(). I tried with the oracle 815 and 817 drivers.

  • Conflicts with Lulu

    With the original release of 'Pages', there is a known conflict with www.lulu.com ( a book publishing site). Apparently .pdf files created from within 'Pages' do not embed Fonts correctly and a 'work around' is published at http://www.anvilwerks.com/

  • Using an 8.0 client with a 6.5 server

    We currently have an application running on AIX and Tuxedo Client 6.5, that connects to a 6.5 server. We are thinking on migrating the application to Linux, and found that Linux is only supported for Tuxedo 7.1 and higher. Would there be any problem

  • How do i disable my ipad

    I am trying to disable my ipad with no success and I have also forgotten by passcode, does anyone know how I can fix both of these issues.