3

I'm having problems with Htmlunit, I disabled JavaScript and set timeout to 10000 before calling getpage, I expected an exception after timeout but htmlunit waits forever.

After some search I realized someone in 2009 had the same problem (Connection timeout not working), he was complaining about "Connection timeout not working" and about some values in timeout not working but until now in 2011 didn't get any answer.

Someone here was asking about what exception is thrown but I think it doesn't throw it always. I can't get an answer from Apache HttpClient setTimeout, either. You can see another person asking about stop in timeout in Terminate or Stop HtmlUnit.

You can see how crazy it is if you try:

milisecReqTimeout = 10;
while(true)
{
    _webclient.setTimeout(milisecReqTimeout);
    milisecReqTimeout = milisecReqTimeout + 10;
    _htmlpage = _webclient.getPage(url);
}
Community
  • 1
  • 1
metoo
  • 41
  • 1
  • 4
  • Save your cookie session data in a file and turn processing parallel loading it on many webclient instances. Maybe it can help you too: http://stackoverflow.com/questions/2237286/how-to-save-htmlunit-cookies-to-a-file – aboutuigrid Jul 23 '11 at 14:43
  • You can use it too [How to make 2 HtmlUnit's WebClients use same cookies?]: http://stackoverflow.com/questions/3043745/how-to-make-2-htmlunits-webclients-use-same-cookies – aboutuigrid Jul 23 '11 at 14:59
  • Why you dont replace HtmlUnit for Jaxer ? –  Jul 23 '11 at 14:19
  • Use the @aboutuigrid comment url http://stackoverflow.com/questions/3043745/how-to-make-2-htmlunits-webclients-use-same-cookies to create an login provider an use it as an visitor. –  Jul 25 '11 at 20:20

2 Answers2

3

     _thewebclient.setWebConnection(new HttpWebConnection(_thewebclient) {
     @Override
     protected synchronized AbstractHttpClient getHttpClient() {
         AbstractHttpClient client = super.getHttpClient();
         if (_TimeoutCliSocket > 0) {
             //Sets the socket timeout (SO_TIMEOUT) in milliseconds to
             //be used when executing the method.
             //A timeout value of zero is interpreted as an infinite timeout.
             //Time that a read operation will block for, before generating 
             //an java.io.InterruptedIOException
             client.getParams().setParameter("http.socket.timeout", 
                                                      _TimeoutCliSocket);
         }
         if (_TimeoutCliConnection > 0) {
             //The timeout in milliseconds used when retrieving an
             // HTTP connection from the HTTP connection manager.
             // Zero means to wait indefinitely.
             client.getParams().setParameter("http.connection-manager.timeout", 
                                                     _TimeoutCliConnection);
         }
         client.getParams().setParameter("http.tcp.nodelay", true);
         return client;
     }
 });

Bye

theytoo
  • 31
  • 2
0

I found, with HttpUnit 1.6.2 setting these

    final HttpClient client = new HttpClient();
    final GetMethod method = new GetMethod(pUrl);

    client.setConnectionTimeout((int) timeout);
    client.setTimeout((int) timeout);

    final int statusCode = client.executeMethod(method);

Seemed to do the trick. Both are deprecated methods. :(

Will
  • 6,179
  • 4
  • 31
  • 49
  • Thanks a lot for it, its so late here in Brazil now 00:19 but tomorrow i will try it, no problem that its deprecated i hope change htmunit layer in future. – metoo Feb 07 '11 at 02:20