You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Mohammad M. Purbo" <pu...@apas.co.jp> on 2002/03/13 09:01:36 UTC

httpclient: timeout

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>