1
1
package org .openstack4j .connectors .resteasy .executors ;
2
2
3
- import java .net .MalformedURLException ;
4
- import java .net .URL ;
5
-
6
3
import org .apache .http .HttpHost ;
7
4
import org .apache .http .client .HttpClient ;
8
- import org .apache .http .conn .params .ConnRoutePNames ;
9
- import org .apache .http .impl .client .DefaultHttpClient ;
10
- import org .apache .http .params .BasicHttpParams ;
11
- import org .apache .http .params .HttpConnectionParams ;
12
- import org .apache .http .params .HttpParams ;
5
+ import org .apache .http .client .config .RequestConfig ;
6
+ import org .apache .http .conn .ssl .NoopHostnameVerifier ;
7
+ import org .apache .http .impl .client .HttpClientBuilder ;
8
+ import org .apache .http .impl .client .HttpClients ;
13
9
import org .jboss .resteasy .client .core .executors .ApacheHttpClient4Executor ;
14
10
import org .openstack4j .core .transport .Config ;
11
+ import org .openstack4j .core .transport .UntrustedSSL ;
12
+
13
+ import java .net .MalformedURLException ;
14
+ import java .net .URL ;
15
15
16
16
/**
17
17
* Default Apache HttpClient based Executor
@@ -25,26 +25,42 @@ public class ApacheHttpClientExecutor extends ApacheHttpClient4Executor {
25
25
}
26
26
27
27
public static ApacheHttpClientExecutor create (Config config ) {
28
-
29
- HttpParams params = new BasicHttpParams ();
30
- if (config .getReadTimeout () > 0 )
31
- HttpConnectionParams .setSoTimeout (params , config .getReadTimeout ());
32
-
33
- if (config .getConnectTimeout () > 0 )
34
- HttpConnectionParams .setConnectionTimeout (params , config .getConnectTimeout ());
35
-
36
- HttpClient client = new DefaultHttpClient (params );
37
-
28
+
29
+ RequestConfig .Builder requestConfigBuilder = RequestConfig .custom ();
30
+
31
+ if (config .getReadTimeout () > 0 ) {
32
+ requestConfigBuilder .setConnectionRequestTimeout (config .getReadTimeout ());
33
+ }
34
+
35
+ if (config .getConnectTimeout () > 0 ) {
36
+ requestConfigBuilder .setConnectTimeout (config .getConnectTimeout ());
37
+ }
38
+
39
+ /*HttpClient client*/
40
+
41
+ HttpClientBuilder httpClientBuilder = HttpClients .custom ();
42
+
43
+ if (config .isIgnoreSSLVerification ()) {
44
+ httpClientBuilder .setSSLContext (UntrustedSSL .getSSLContext ());
45
+ httpClientBuilder .setSSLHostnameVerifier (new NoopHostnameVerifier ());
46
+ }
47
+
48
+ if (config .getHostNameVerifier () != null ) {
49
+ httpClientBuilder .setSSLHostnameVerifier (config .getHostNameVerifier ());
50
+ }
51
+
38
52
if (config .getProxy () != null ) {
39
53
try {
40
54
URL url = new URL (config .getProxy ().getHost ());
41
55
HttpHost proxy = new HttpHost (url .getHost (), config .getProxy ().getPort (), url .getProtocol ());
42
- client . getParams (). setParameter ( ConnRoutePNames . DEFAULT_PROXY , proxy );
56
+ requestConfigBuilder . setProxy ( proxy );
43
57
} catch (MalformedURLException e ) {
44
58
e .printStackTrace ();
45
59
}
46
60
}
47
-
61
+
62
+ httpClientBuilder .setDefaultRequestConfig (requestConfigBuilder .build ());
63
+ HttpClient client = httpClientBuilder .build ();
48
64
return new ApacheHttpClientExecutor (client );
49
65
}
50
66
0 commit comments