Hi Vitaly,
If you are want to control the connect timeout you need to control the
socket creation with a custom protocol socket factory. When creating the
socket; you can then specify a connection timeout of 10000 ms.
<code>
Protocol http = new Protocol("http", new MySocketFactory(), 80);
public class MySocketFactory {
private static final int CONNECT_TIMEOUT = 10000;
...
public Socket createSocket(final String host, final int port) throws
IOException,
UnknownHostException {
final InetSocketAddress sa = new InetSocketAddress(host, port):
final Socket s = new Socket();
s.connect(sa, CONNECT_TIMEOUT);
return s;
}
...
}
</code>
On 8/15/07, Oleg Kalnichevski <[EMAIL PROTECTED]> wrote:
>
> On Wed, 2007-08-15 at 17:56 +0300, Vitaly Baranovsky wrote:
> > Good day!
> >
> > Connection timeouts of httpClient in my program doesn't works. I set
> > timeout to 10 000 milliseconds, but my program waits for about 65
> > seconds before answering.
>
> ...
>
> > Here is the code of my class:
> >
> > public class HttpGetter {
> >
> > private static final int DEFAULT_SOCKET_TIMEOUT = 10000;
> > private HttpClient httpClient;
> > private GetMethod method;
> >
> > public HttpGetter() {
> > super();
> > MultiThreadedHttpConnectionManager cm = new
> > MultiThreadedHttpConnectionManager();
> > cm.getParams().setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
> >
>
> Hi Vitaly,
>
> On top of what Pete Keyes just said, in your code you are setting a
> socket timeout, not a connect timeout. No wonder you are not getting the
> expected result.
>
> Oleg
>
>
> > httpClient = new HttpClient(cm);
> > }
> >
> > private String getFromURLAsString(String url) throws HttpException,
> > IOException {
> > URI uri = new URI(url, false);
> > method = new GetMethod(uri.getEscapedURI());
> > method.getParams().setSoTimeout(DEFAULT_SOCKET_TIMEOUT);
> > int result = httpClient.executeMethod(method);
> > return method.getResponseBodyAsString();;
> > }
> > }
> >
> >
> >
> > Here is the code of my TestCase:
> >
> > public class HttpGetterTest extends TestCase {
> > public void testGetFromUrlAsString() throws HttpException,
> IOException{
> > HttpGetter httpGetter = new HttpGetter();
> > System.out.println(httpGetter.getFromURLAsString("
> http://google.com"));
> > }
> > }
> >
> >
> > Why timeouts doesn't works?
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
--------------------------------------------------------------------------------
Raymond Kroeker
thinkParity Solutions Inc.