commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mohammad M. Purbo" <pu...@apas.co.jp>
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());
connection.setSoTimeout(timeout);
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
HttpMethodBase).

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) {
  _socket.setSoTimeout(_timeout);
}

Did i miss something?

Thank you,

M. Purbo


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message