Browse Source

HttpClientConnection: Don't use deprecated HttpClient classes

- 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>
stable-4.6
David Pursehouse 8 years ago committed by Matthias Sohn
parent
commit
cf5b40fb81
  1. 36
      org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF
  2. 69
      org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java

36
org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF

@ -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

69
org.eclipse.jgit.http.apache/src/org/eclipse/jgit/transport/http/apache/HttpClientConnection.java

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

Loading…
Cancel
Save