hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Albert Kam" <moonblade.w...@gmail.com>
Subject No Exception occurs and Timeout doesnt work .. helpp ..
Date Fri, 03 Aug 2007 11:40:01 GMT
Dear all,

I simulated these steps in a normal lan network, this is the normal steps,
and they work fine as expected :
1. I start this program which uses HttpClient to send and receive from/to a
remote servlet
2. The servlet receives and do some database processes
3. The servlet sends the data to the HttpClient program
4. The servlet commits the database transaction
5. The response from the servlet received and printed by the HttpClient
program.

And then i re-simulated these steps, trying to simulate a broken network or
internet :
1. I start this program which uses HttpClient to send and receive from/to a
remote servlet
2. The servlet receives and sleep for 5 seconds
3. In those 5 seconds, i unplugged my utp cable, so that those 2 pc-s are
not connected
4. After 5 seconds, the servlet do some database processes
5. The servlet sends the data to the HttpClient program
6. The servlet commits the database transaction
7. The HttpClient program freezes, waiting (seems like forever), although i
already set the timeout attribute in the HttpClient program.

The ideal that i'm expecting is this :
1. I start this program which uses HttpClient to send and receive from/to a
remote servlet
2. The servlet receives and sleep for 5 seconds
3. In those 5 seconds, i unplugged my utp cable, so that those 2 pc-s are
not connected
4. After 5 seconds, the servlet do some database processes
5. The servlet sends the data to the HttpClient program, but exception
occurs, because the cable has been unplugged(in this case), or the internet
is down(perhaps in the future)
6. The servlet rollbacks the database transaction in the catch block instead
of committing it
7. The HttpClient program times out after xx seconds based on what i've set
in the program.

Is it possible to achieve what i'm expecting ? Although the cable has been
unplugged, there's no exception while sending data from the servlet to the
program. And the timeout parameter doesnt seem to work. Helpp ..

The source code of the HttpClient program is this :

HttpClient client = new HttpClient();
client.getHttpConnectionManager().getParams().setConnectionTimeout(10000);
//client.getHttpConnectionManager().getParams().setStaleCheckingEnabled(true);
PostMethod method = new PostMethod("
http://192.xx.xx.xx:8080/xx/servlet/common.XxxxServlet?taskId=test");
method.setRequestEntity(new ObjectRequestEntity(Integer.valueOf("1111")));

try {
    int statusCode = client.executeMethod(method);

    if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: " + method.getStatusLine());
    }

    // Read the response body.
    InputStream in = method.getResponseBodyAsStream();
    ObjectInputStream objIn = new ObjectInputStream(in);
    GZIPInputStream gzipIn = new GZIPInputStream(objIn);
    Object object = objIn.readObject();
    System.out.println("RESULT : " + object.getClass() + " : " + object);

} catch (HttpException e) {
    System.err.println("Fatal protocol violation: " + e.getMessage());
    e.printStackTrace();
} catch (IOException e) {
    System.err.println("Fatal transport error: " + e.getMessage());
    e.printStackTrace();
} catch (ClassNotFoundException e) {
    e.printStackTrace();
} finally {
    // Release the connection.
    method.releaseConnection();
}

Every good wish,
Albert Kam

-- 
All meetings end in partings
That which rises must fall
That which is collected will be dispersed
Birth ends with death

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