srijiths

HttpClient Connection time out

Jan 3rd, 2012
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. This is my code snippet
  2.  
  3. HttpParams httpParams = new BasicHttpParams();
  4. HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
  5.  
  6. // set request params
  7. httpParams.setParameter("http.language.Accept-Language", "en-us");
  8. httpParams.setParameter("http.protocol.content-charset", "UTF-8");
  9. httpParams.setParameter("Accept", "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
  10. httpParams.setParameter("http.connection.stalecheck", false); // turn off stale check checking for performance reasons
  11.  
  12.  
  13. SchemeRegistry schemeRegistry = new SchemeRegistry();
  14. schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
  15. schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
  16.  
  17. final ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
  18. httpClient = new DefaultHttpClient(cm, httpParams);
  19.  
  20. HttpConnectionParams.setConnectionTimeout(httpParams, 1000);
  21. HttpConnectionParams.setSoTimeout(httpParams, 10000);
  22.  
  23. httpClient.getParams().setParameter("http.connection.timeout", 1000);
  24. httpClient.getParams().setParameter("http.tcp.nodelay", true);
  25.  
  26.  
  27. and this is my log
  28. 2012-01-04 11:12:05 HtmlFetch [DEBUG] Initializing HttpClient
  29. 2012-01-04 11:12:05 SingleClientConnManager [DEBUG] Get connection for route HttpRoute[{}->http://192.168.2.59]
  30. 2012-01-04 11:12:05 DefaultClientConnectionOperator [DEBUG] Connecting to 192.168.2.59:80
  31. 2012-01-04 11:12:05 RequestAddCookies [DEBUG] CookieSpec selected: best-match
  32. 2012-01-04 11:12:05 RequestAuthCache [DEBUG] Auth cache not set in the context
  33. 2012-01-04 11:12:05 DefaultHttpClient [DEBUG] Attempt 1 to execute request
  34. 2012-01-04 11:12:05 DefaultClientConnection [DEBUG] Sending request: GET /test.php HTTP/1.1
  35. 2012-01-04 11:12:05 wire [DEBUG] >> "GET /test.php HTTP/1.1[\r][\n]"
  36. 2012-01-04 11:12:05 wire [DEBUG] >> "Host: 192.168.2.59[\r][\n]"
  37. 2012-01-04 11:12:05 wire [DEBUG] >> "Connection: Keep-Alive[\r][\n]"
  38. 2012-01-04 11:12:05 wire [DEBUG] >> "User-Agent: Apache-HttpClient/4.1.2 (java 1.5)[\r][\n]"
  39. 2012-01-04 11:12:05 wire [DEBUG] >> "[\r][\n]"
  40. 2012-01-04 11:12:05 headers [DEBUG] >> GET /test.php HTTP/1.1
  41. 2012-01-04 11:12:05 headers [DEBUG] >> Host: 192.168.2.59
  42. 2012-01-04 11:12:05 headers [DEBUG] >> Connection: Keep-Alive
  43. 2012-01-04 11:12:05 headers [DEBUG] >> User-Agent: Apache-HttpClient/4.1.2 (java 1.5)
  44. 2012-01-04 11:12:15 wire [DEBUG] << "HTTP/1.1 200 OK[\r][\n]"
  45. 2012-01-04 11:12:15 wire [DEBUG] << "Date: Wed, 04 Jan 2012 05:42:05 GMT[\r][\n]"
  46. 2012-01-04 11:12:15 wire [DEBUG] << "Server: Apache/2.2.17 (Ubuntu)[\r][\n]"
  47. 2012-01-04 11:12:15 wire [DEBUG] << "X-Powered-By: PHP/5.3.5-1ubuntu7.4[\r][\n]"
  48. 2012-01-04 11:12:15 wire [DEBUG] << "Vary: Accept-Encoding[\r][\n]"
  49. 2012-01-04 11:12:15 wire [DEBUG] << "Content-Length: 0[\r][\n]"
  50. 2012-01-04 11:12:15 wire [DEBUG] << "Keep-Alive: timeout=15, max=100[\r][\n]"
  51. 2012-01-04 11:12:15 wire [DEBUG] << "Connection: Keep-Alive[\r][\n]"
  52. 2012-01-04 11:12:15 wire [DEBUG] << "Content-Type: text/html[\r][\n]"
  53. 2012-01-04 11:12:15 wire [DEBUG] << "[\r][\n]"
  54. 2012-01-04 11:12:15 DefaultClientConnection [DEBUG] Receiving response: HTTP/1.1 200 OK
  55. 2012-01-04 11:12:15 headers [DEBUG] << HTTP/1.1 200 OK
  56. 2012-01-04 11:12:15 headers [DEBUG] << Date: Wed, 04 Jan 2012 05:42:05 GMT
  57. 2012-01-04 11:12:15 headers [DEBUG] << Server: Apache/2.2.17 (Ubuntu)
  58. 2012-01-04 11:12:15 headers [DEBUG] << X-Powered-By: PHP/5.3.5-1ubuntu7.4
  59. 2012-01-04 11:12:15 headers [DEBUG] << Vary: Accept-Encoding
  60. 2012-01-04 11:12:15 headers [DEBUG] << Content-Length: 0
  61. 2012-01-04 11:12:15 headers [DEBUG] << Keep-Alive: timeout=15, max=100
  62. 2012-01-04 11:12:15 headers [DEBUG] << Connection: Keep-Alive
  63. 2012-01-04 11:12:15 headers [DEBUG] << Content-Type: text/html
  64. 2012-01-04 11:12:15 ThreadSafeClientConnManager [DEBUG] Shutting down
  65. 2012-01-04 11:12:15 DefaultHttpClient [DEBUG] Connection can be kept alive for 15000 MILLISECONDS
  66. 2012-01-04 11:12:15 SingleClientConnManager [DEBUG] Releasing connection org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@147c1db
  67.  
  68. Here DefaultHttpClient [DEBUG] Connection can be kept alive for 15000 MILLISECONDS . Is this default time out ???
Advertisement
Add Comment
Please, Sign In to add comment