]> source.dussan.org Git - jgit.git/commitdiff
HttpClientConnection: Don't use deprecated HttpClient classes 05/81505/4
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 20 Sep 2016 19:19:44 +0000 (21:19 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Thu, 22 Sep 2016 07:46:23 +0000 (09:46 +0200)
- raise minimum version for HttpClient packages to 4.3 since some of the
used classes aren't available in older versions
- recompute OSGi uses clauses

Change-Id: I8f0bff1433762561e02f7439db27a6a9e846c290
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF
org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java

index 4d0c08a98b060474b304da3a680463ff5a78192a..1b4d4b12129c88deb664c874d18247dbf4d67eb6 100644 (file)
@@ -7,25 +7,31 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Bundle-Localization: plugin
 Bundle-Vendor: %Provider-Name
 Bundle-ActivationPolicy: lazy
-Import-Package: org.apache.http;version="[4.1.0,5.0.0)",
- org.apache.http.client;version="[4.1.0,5.0.0)",
- org.apache.http.client.methods;version="[4.1.0,5.0.0)",
- org.apache.http.client.params;version="[4.1.0,5.0.0)",
- org.apache.http.conn;version="[4.1.0,5.0.0)",
- org.apache.http.conn.params;version="[4.1.0,5.0.0)",
- org.apache.http.conn.scheme;version="[4.1.0,5.0.0)",
- org.apache.http.conn.ssl;version="[4.1.0,5.0.0)",
- org.apache.http.entity;version="[4.1.0,5.0.0)",
- org.apache.http.impl.client;version="[4.1.0,5.0.0)",
- org.apache.http.impl.client.cache;version="[4.1.0,5.0.0)",
- org.apache.http.params;version="[4.1.0,5.0.0)",
+Import-Package: org.apache.http;version="[4.3.0,5.0.0)",
+ org.apache.http.client;version="[4.3.0,5.0.0)",
+ org.apache.http.client.config;version="[4.3.0,5.0.0)",
+ org.apache.http.client.methods;version="[4.3.0,5.0.0)",
+ org.apache.http.client.params;version="[4.3.0,5.0.0)",
+ org.apache.http.config;version="[4.3.0,5.0.0)",
+ org.apache.http.conn;version="[4.3.0,5.0.0)",
+ org.apache.http.conn.params;version="[4.3.0,5.0.0)",
+ org.apache.http.conn.scheme;version="[4.3.0,5.0.0)",
+ org.apache.http.conn.socket;version="[4.3.0,5.0.0)",
+ org.apache.http.conn.ssl;version="[4.3.0,5.0.0)",
+ org.apache.http.entity;version="[4.3.0,5.0.0)",
+ org.apache.http.impl.client;version="[4.3.0,5.0.0)",
+ org.apache.http.impl.client.cache;version="[4.3.0,5.0.0)",
+ org.apache.http.impl.conn;version="[4.3.0,5.0.0)",
+ org.apache.http.params;version="[4.3.0,5.0.0)",
  org.eclipse.jgit.nls;version="[4.6.0,4.7.0)",
  org.eclipse.jgit.transport.http;version="[4.6.0,4.7.0)",
  org.eclipse.jgit.util;version="[4.6.0,4.7.0)"
 Export-Package: org.eclipse.jgit.transport.http.apache;version="4.6.0";
-  uses:="org.eclipse.jgit.transport.http,
-   javax.net.ssl,
-   org.apache.http.client,
+  uses:="org.apache.http.client,
+   org.eclipse.jgit.transport.http,
+   org.apache.http.entity,
    org.apache.http.client.methods,
+   javax.net.ssl,
+   org.eclipse.jgit.util,
    org.apache.http",
  org.eclipse.jgit.transport.http.apache.internal;x-internal:=true
index 2d9d17a890281eaeb0e4ed810cbe78306a501da2..6543bf66107fe512cde38505d6ae2e60650dc153 100644 (file)
@@ -80,19 +80,20 @@ import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.ClientProtocolException;
 import org.apache.http.client.HttpClient;
+import org.apache.http.client.config.RequestConfig;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.client.methods.HttpHead;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.conn.params.ConnRoutePNames;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
 import org.apache.http.conn.ssl.X509HostnameVerifier;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.params.CoreConnectionPNames;
-import org.apache.http.params.HttpParams;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.BasicHttpClientConnectionManager;
 import org.eclipse.jgit.transport.http.HttpConnection;
 import org.eclipse.jgit.transport.http.apache.internal.HttpApacheText;
 import org.eclipse.jgit.util.TemporaryBuffer;
@@ -131,29 +132,37 @@ public class HttpClientConnection implements HttpConnection {
        SSLContext ctx;
 
        private HttpClient getClient() {
-               if (client == null)
-                       client = new DefaultHttpClient();
-               HttpParams params = client.getParams();
-               if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
-                       isUsingProxy = true;
-                       InetSocketAddress adr = (InetSocketAddress) proxy.address();
-                       params.setParameter(ConnRoutePNames.DEFAULT_PROXY,
-                                       new HttpHost(adr.getHostName(), adr.getPort()));
-               }
-               if (timeout != null)
-                       params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT,
-                                       timeout.intValue());
-               if (readTimeout != null)
-                       params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT,
-                                       readTimeout.intValue());
-               if (followRedirects != null)
-                       params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS,
-                                       followRedirects.booleanValue());
-               if (hostnameverifier != null) {
-                       SSLSocketFactory sf;
-                       sf = new SSLSocketFactory(getSSLContext(), hostnameverifier);
-                       Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$
-                       client.getConnectionManager().getSchemeRegistry().register(https);
+               if (client == null) {
+                       HttpClientBuilder clientBuilder = HttpClients.custom();
+                       RequestConfig.Builder configBuilder = RequestConfig.custom();
+                       if (proxy != null && !Proxy.NO_PROXY.equals(proxy)) {
+                               isUsingProxy = true;
+                               InetSocketAddress adr = (InetSocketAddress) proxy.address();
+                               clientBuilder.setProxy(
+                                               new HttpHost(adr.getHostName(), adr.getPort()));
+                       }
+                       if (timeout != null) {
+                               configBuilder.setConnectTimeout(timeout.intValue());
+                       }
+                       if (readTimeout != null) {
+                               configBuilder.setSocketTimeout(readTimeout.intValue());
+                       }
+                       if (followRedirects != null) {
+                               configBuilder
+                                               .setRedirectsEnabled(followRedirects.booleanValue());
+                       }
+                       if (hostnameverifier != null) {
+                               SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(
+                                               getSSLContext(), hostnameverifier);
+                               clientBuilder.setSSLSocketFactory(sslConnectionFactory);
+                               Registry<ConnectionSocketFactory> registry = RegistryBuilder
+                                               .<ConnectionSocketFactory> create()
+                                               .register("https", sslConnectionFactory).build();
+                               clientBuilder.setConnectionManager(
+                                               new BasicHttpClientConnectionManager(registry));
+                       }
+                       clientBuilder.setDefaultRequestConfig(configBuilder.build());
+                       client = clientBuilder.build();
                }
 
                return client;