hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mathias Cianci <mcia...@axecibles.com>
Subject Re: timeout while waiting from reponse body ?
Date Thu, 12 Aug 2004 13:33:14 GMT
Ok, so if I can ask stupid questions, I will not obstruct myself :o)

Here is a light version of my code :

    HttpClient client = new HttpClient();
    client.setTimeout(60000);
           
    HttpMethod method = null;
    try {
        method = new MyGetMethod(adresse);
    } catch(Exception e) {
        new Erreur("21;Erreur lors du décodage de l'URL
    "+e.getMessage(), "Pas de code source", this);
    }

    // Execute the method.
    int statusCode = -1;
    // We will retry up to 3 times.
    for (int attempt = 0; statusCode == -1 && attempt < 3; attempt++) {
        try {
            statusCode = client.executeMethod(method);
        } catch (HttpRecoverableException e) {
            System.err.println("A recoverable exception occurred,
    retrying." + e.getMessage());
        } catch (IOException e) {
            System.err.println("Failed to download file.");
        }
    }

    // Check that we didn't run out of retries.
    if (statusCode == -1) {
        System.err.println("Failed to recover from exception.");
    }

    // Read the response body.
    try {
        byte[] responseBody = method.getResponseBody();
        leCode.set(new String(responseBody, this.getCodageUrl()));
    } catch (SocketTimeoutException e) {
        System.err.println("timeout error" + e.getMessage());
    } catch (Exception e) {
        System.out.println("mauvais encodage");
    }

    // Release the connection.
    method.releaseConnection();


The problem is that hte method.getReponseBody can't throw a 
SocketTimeoutException but that's this method who is giving me problems



Kalnichevski, Oleg a écrit :

>You are more than welcome to ask any kind of HttpClient related questions
>
>Oleg
>
>-----Original Message-----
>From: Mathias Cianci [mailto:mcianci@axecibles.com]
>Sent: Thursday, August 12, 2004 3:02 PM
>To: Commons HttpClient Project
>Subject: Re: timeout while waiting from reponse body ?
>
>
>Thank you Oleg and excuse me for asking such questions.
>I was searching with the TimeoutController class, and I've not seen the
>
>obvious answer.
>
>Kalnichevski, Oleg a écrit :
>
>  
>
>>Setting socket timeout to a positive value will do the trick
>>
>>HttpClient client = new HttpClient();
>>client.setTimeout(60000); // 60 sec timeout
>>    
>>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message