polish used http client
authorEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 15:34:26 +0000 (19:34 +0400)
committerEugene Petrenko <eugene.petrenko@gmail.com>
Mon, 15 Aug 2011 15:34:26 +0000 (19:34 +0400)
nuget-server/src/jetbrains/buildServer/nuget/server/feed/reader/impl/FeedHttpClientHolder.java

index 9e251c2f0c52a91fba89f99c3dac7a32bafc0796..9fabd558b6dfc48bd13370a6f2f0cd9d41c7fa25 100644 (file)
@@ -20,8 +20,11 @@ import jetbrains.buildServer.version.ServerVersionHolder;
 import org.apache.http.HttpResponse;\r
 import org.apache.http.client.HttpClient;\r
 import org.apache.http.client.methods.HttpUriRequest;\r
+import org.apache.http.impl.client.ContentEncodingHttpClient;\r
 import org.apache.http.impl.client.DefaultHttpClient;\r
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;\r
 import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;\r
+import org.apache.http.params.BasicHttpParams;\r
 import org.apache.http.params.HttpConnectionParams;\r
 import org.apache.http.params.HttpParams;\r
 import org.apache.http.params.HttpProtocolParams;\r
@@ -37,14 +40,19 @@ public class FeedHttpClientHolder implements FeedClient {
   private final HttpClient myClient;\r
 \r
   public FeedHttpClientHolder() {\r
-    myClient = new DefaultHttpClient(new ThreadSafeClientConnManager());\r
-    final HttpParams params = myClient.getParams();\r
+    final String serverVersion = ServerVersionHolder.getVersion().getDisplayVersion();\r
 \r
-    HttpConnectionParams.setConnectionTimeout(params, 10000);\r
-    HttpConnectionParams.setSoTimeout(params, 10000);\r
+    HttpParams ps = new BasicHttpParams();\r
+    DefaultHttpClient.setDefaultHttpParams(ps);\r
 \r
-    final String serverVersion = ServerVersionHolder.getVersion().getDisplayVersion();\r
-    HttpProtocolParams.setUserAgent(params, "JetBrains TeamCity " + serverVersion);\r
+    HttpConnectionParams.setConnectionTimeout(ps, 10000);\r
+    HttpConnectionParams.setSoTimeout(ps, 10000);\r
+    HttpProtocolParams.setUserAgent(ps, "JetBrains TeamCity " + serverVersion);\r
+\r
+    final DefaultHttpClient client = new ContentEncodingHttpClient(new ThreadSafeClientConnManager(), ps);\r
+    client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(3, true));\r
+\r
+    myClient = client;\r
   }\r
 \r
   @NotNull\r