commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mohammad M. Purbo" <>
Subject httpclient: timeout
Date Wed, 13 Mar 2002 08:01:36 GMT
Hi All, i was just joining & have a question/suggestion.

i downloaded commons-httpclient source code sometimes ago (nightly build:
20020307) to try to use it in one of my project, in which i need to set the
timeout for a connection.

i wrote something like:

import org.apache.commons.httpclient.*;
HttpConnectionManager httpconn = ........
HttpUrlMethod method = ......
int timeout = 60000;

HttpConnection connection = httpconn.getConnection(method.getUrl());
int status = method.execute(getState(),connection);

which of course wouldn't work because HttpConnectionManger.getConnection is
not returning opened connection, and the connection wouldn't be opened until
the execution of HttpMethodBase.execute.

now, i couldn't find any way to set the timeout so that it can be set to the
HttpConnection once it's opened inside HttpMethodBase.execute (except by
overriding the execute method in my own Method-descendant class, which is a
bit too much because it's almost as good as writing the whole

So I made a patch temporarily in HttpConnection:

1. add private member:
private int _timeout = -1;

2. update setSoTimeout():
public void setSoTimeout(int timeout) throws SocketException,
IllegalStateException {
    _timeout = timeout;

3. update open(), and add the following lines just before _open = true;
if (_timeout > 0) {

Did i miss something?

Thank you,

M. Purbo

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message