hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vitaly Baranovsky" <vitaly.baranovsk...@gmail.com>
Subject Why connection timeouts doesn't works?
Date Wed, 15 Aug 2007 14:56:45 GMT
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 stacktrace of my unit test:
java.net.SocketException: Network is unreachable: connect
 at java.net.PlainSocketImpl.socketConnect(Native Method)
 at java.net.PlainSocketImpl.doConnect(Unknown Source)
 at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
 at java.net.PlainSocketImpl.connect(Unknown Source)
 at java.net.SocksSocketImpl.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at java.net.Socket.connect(Unknown Source)
 at java.net.Socket.<init>(Unknown Source)
 at java.net.Socket.<init>(Unknown Source)
 at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(Unknown
Source)
 at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(Unknown
Source)
 at org.apache.commons.httpclient.HttpConnection.open(Unknown Source)
 at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(Unknown
Source)
 at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Unknown
Source)
 at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Unknown
Source)
 at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
 at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
 at net.liga.commons.HttpGetter.runGetCore(HttpGetter.java:58)
 at net.liga.commons.HttpGetter.getFromURLAsString(HttpGetter.java:88)
 at net.liga.commons.test.HttpGetterTest.testGetFromUrlAsString(HttpGetterTest.java:38)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at junit.framework.TestCase.runTest(TestCase.java:164)
 at junit.framework.TestCase.runBare(TestCase.java:130)
 at junit.framework.TestResult$1.protect(TestResult.java:106)
 at junit.framework.TestResult.runProtected(TestResult.java:124)
 at junit.framework.TestResult.run(TestResult.java:109)
 at junit.framework.TestCase.run(TestCase.java:120)
 at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
 at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
 at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



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);

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


Mime
View raw message