25
25
26
26
import javax .net .ssl .HostnameVerifier ;
27
27
import javax .net .ssl .SSLContext ;
28
- import javax .net .ssl .SSLEngine ;
29
28
30
- import java .security .GeneralSecurityException ;
31
29
import java .util .Collections ;
32
30
import java .util .LinkedList ;
33
31
import java .util .List ;
@@ -68,7 +66,6 @@ public class AsyncHttpClientConfig {
68
66
protected ExecutorService applicationThreadPool ;
69
67
protected ProxyServerSelector proxyServerSelector ;
70
68
protected SSLContext sslContext ;
71
- protected SSLEngineFactory sslEngineFactory ;
72
69
protected AsyncHttpProviderConfig <?, ?> providerConfig ;
73
70
protected ConnectionsPool <?, ?> connectionsPool ;
74
71
protected Realm realm ;
@@ -86,6 +83,7 @@ public class AsyncHttpClientConfig {
86
83
protected boolean useRelativeURIsWithSSLProxies ;
87
84
protected int maxConnectionLifeTimeInMs ;
88
85
protected TimeConverter timeConverter ;
86
+ protected boolean acceptAnyCertificate ;
89
87
90
88
protected AsyncHttpClientConfig () {
91
89
}
@@ -106,7 +104,6 @@ private AsyncHttpClientConfig(int maxTotalConnections,
106
104
ExecutorService applicationThreadPool ,
107
105
ProxyServerSelector proxyServerSelector ,
108
106
SSLContext sslContext ,
109
- SSLEngineFactory sslEngineFactory ,
110
107
AsyncHttpProviderConfig <?, ?> providerConfig ,
111
108
ConnectionsPool <?, ?> connectionsPool , Realm realm ,
112
109
List <RequestFilter > requestFilters ,
@@ -121,7 +118,8 @@ private AsyncHttpClientConfig(int maxTotalConnections,
121
118
int ioThreadMultiplier ,
122
119
boolean strict302Handling ,
123
120
boolean useRelativeURIsWithSSLProxies ,
124
- TimeConverter timeConverter ) {
121
+ TimeConverter timeConverter , //
122
+ boolean acceptAnyCertificate ) {
125
123
126
124
this .maxTotalConnections = maxTotalConnections ;
127
125
this .maxConnectionPerHost = maxConnectionPerHost ;
@@ -137,7 +135,6 @@ private AsyncHttpClientConfig(int maxTotalConnections,
137
135
this .userAgent = userAgent ;
138
136
this .allowPoolingConnection = keepAlive ;
139
137
this .sslContext = sslContext ;
140
- this .sslEngineFactory = sslEngineFactory ;
141
138
this .providerConfig = providerConfig ;
142
139
this .connectionsPool = connectionsPool ;
143
140
this .realm = realm ;
@@ -161,6 +158,7 @@ private AsyncHttpClientConfig(int maxTotalConnections,
161
158
this .proxyServerSelector = proxyServerSelector ;
162
159
this .disableUrlEncodingForBoundedRequests = disableUrlEncodingForBoundedRequests ;
163
160
this .timeConverter = timeConverter ;
161
+ this .acceptAnyCertificate = acceptAnyCertificate ;
164
162
}
165
163
166
164
/**
@@ -310,28 +308,6 @@ public SSLContext getSSLContext() {
310
308
return connectionsPool ;
311
309
}
312
310
313
- /**
314
- * Return an instance of {@link SSLEngineFactory} used for SSL connection.
315
- *
316
- * @return an instance of {@link SSLEngineFactory} used for SSL connection.
317
- */
318
- public SSLEngineFactory getSSLEngineFactory () {
319
- if (sslEngineFactory == null ) {
320
- return new SSLEngineFactory () {
321
- public SSLEngine newSSLEngine () {
322
- if (sslContext != null ) {
323
- SSLEngine sslEngine = sslContext .createSSLEngine ();
324
- sslEngine .setUseClientMode (true );
325
- return sslEngine ;
326
- } else {
327
- return null ;
328
- }
329
- }
330
- };
331
- }
332
- return sslEngineFactory ;
333
- }
334
-
335
311
/**
336
312
* Return the {@link com.ning.http.client.AsyncHttpProviderConfig}
337
313
*
@@ -491,12 +467,19 @@ public int getMaxConnectionLifeTimeInMs() {
491
467
}
492
468
493
469
/**
494
- * @return 1.8.2
470
+ * since 1.8.2
495
471
*/
496
472
public TimeConverter getTimeConverter () {
497
473
return timeConverter ;
498
474
}
499
475
476
+ /**
477
+ * since 1.9.0
478
+ */
479
+ public boolean isAcceptAnyCertificate () {
480
+ return acceptAnyCertificate ;
481
+ }
482
+
500
483
/**
501
484
* Builder for an {@link AsyncHttpClient}
502
485
*/
@@ -525,11 +508,11 @@ public static class Builder {
525
508
private boolean removeQueryParamOnRedirect = defaultRemoveQueryParamOnRedirect ();
526
509
private boolean strict302Handling = defaultStrict302Handling ();
527
510
private HostnameVerifier hostnameVerifier = defaultHostnameVerifier ();
511
+ private boolean acceptAnyCertificate = defaultAcceptAnyCertificate ();
528
512
529
513
private ExecutorService applicationThreadPool ;
530
514
private ProxyServerSelector proxyServerSelector = null ;
531
515
private SSLContext sslContext ;
532
- private SSLEngineFactory sslEngineFactory ;
533
516
private AsyncHttpProviderConfig <?, ?> providerConfig ;
534
517
private ConnectionsPool <?, ?> connectionsPool ;
535
518
private Realm realm ;
@@ -713,31 +696,13 @@ public Builder setProxyServer(ProxyServer proxyServer) {
713
696
return this ;
714
697
}
715
698
716
- /**
717
- * Set the {@link SSLEngineFactory} for secure connection.
718
- *
719
- * @param sslEngineFactory the {@link SSLEngineFactory} for secure connection
720
- * @return a {@link Builder}
721
- */
722
- public Builder setSSLEngineFactory (SSLEngineFactory sslEngineFactory ) {
723
- this .sslEngineFactory = sslEngineFactory ;
724
- return this ;
725
- }
726
-
727
699
/**
728
700
* Set the {@link SSLContext} for secure connection.
729
701
*
730
702
* @param sslContext the {@link SSLContext} for secure connection
731
703
* @return a {@link Builder}
732
704
*/
733
705
public Builder setSSLContext (final SSLContext sslContext ) {
734
- this .sslEngineFactory = new SSLEngineFactory () {
735
- public SSLEngine newSSLEngine () throws GeneralSecurityException {
736
- SSLEngine sslEngine = sslContext .createSSLEngine ();
737
- sslEngine .setUseClientMode (true );
738
- return sslEngine ;
739
- }
740
- };
741
706
this .sslContext = sslContext ;
742
707
return this ;
743
708
}
@@ -998,6 +963,11 @@ public Builder setTimeConverter(TimeConverter timeConverter) {
998
963
return this ;
999
964
}
1000
965
966
+ public Builder setAcceptAnyCertificate (boolean acceptAnyCertificate ) {
967
+ this .acceptAnyCertificate = acceptAnyCertificate ;
968
+ return this ;
969
+ }
970
+
1001
971
/**
1002
972
* Create a config builder with values taken from the given prototype configuration.
1003
973
*
@@ -1018,7 +988,6 @@ public Builder(AsyncHttpClientConfig prototype) {
1018
988
realm = prototype .getRealm ();
1019
989
requestTimeoutInMs = prototype .getRequestTimeoutInMs ();
1020
990
sslContext = prototype .getSSLContext ();
1021
- sslEngineFactory = prototype .getSSLEngineFactory ();
1022
991
userAgent = prototype .getUserAgent ();
1023
992
followRedirect = prototype .isFollowRedirect ();
1024
993
compressionEnabled = prototype .isCompressionEnabled ();
@@ -1041,6 +1010,7 @@ public Builder(AsyncHttpClientConfig prototype) {
1041
1010
hostnameVerifier = prototype .getHostnameVerifier ();
1042
1011
strict302Handling = prototype .isStrict302Handling ();
1043
1012
timeConverter = prototype .timeConverter ;
1013
+ acceptAnyCertificate = prototype .acceptAnyCertificate ;
1044
1014
}
1045
1015
1046
1016
/**
@@ -1073,40 +1043,39 @@ public Thread newThread(Runnable r) {
1073
1043
proxyServerSelector = ProxyServerSelector .NO_PROXY_SELECTOR ;
1074
1044
}
1075
1045
1076
- return new AsyncHttpClientConfig (maxTotalConnections ,
1077
- maxConnectionPerHost ,
1078
- connectionTimeOutInMs ,
1079
- webSocketIdleTimeoutInMs ,
1080
- idleConnectionInPoolTimeoutInMs ,
1081
- idleConnectionTimeoutInMs ,
1082
- requestTimeoutInMs ,
1083
- maxConnectionLifeTimeInMs ,
1084
- followRedirect ,
1085
- maxDefaultRedirects ,
1086
- compressionEnabled ,
1087
- userAgent ,
1088
- allowPoolingConnection ,
1089
- applicationThreadPool ,
1090
- proxyServerSelector ,
1091
- sslContext ,
1092
- sslEngineFactory ,
1093
- providerConfig ,
1094
- connectionsPool ,
1095
- realm ,
1096
- requestFilters ,
1097
- responseFilters ,
1098
- ioExceptionFilters ,
1099
- requestCompressionLevel ,
1100
- maxRequestRetry ,
1101
- allowSslConnectionPool ,
1102
- disableUrlEncodingForBoundedRequests ,
1103
- removeQueryParamOnRedirect ,
1104
- hostnameVerifier ,
1105
- ioThreadMultiplier ,
1106
- strict302Handling ,
1107
- useRelativeURIsWithSSLProxies ,
1108
- timeConverter );
1046
+ return new AsyncHttpClientConfig (maxTotalConnections , //
1047
+ maxConnectionPerHost , //
1048
+ connectionTimeOutInMs , //
1049
+ webSocketIdleTimeoutInMs , //
1050
+ idleConnectionInPoolTimeoutInMs , //
1051
+ idleConnectionTimeoutInMs , //
1052
+ requestTimeoutInMs , //
1053
+ maxConnectionLifeTimeInMs , //
1054
+ followRedirect , //
1055
+ maxDefaultRedirects , //
1056
+ compressionEnabled , //
1057
+ userAgent , //
1058
+ allowPoolingConnection , //
1059
+ applicationThreadPool , //
1060
+ proxyServerSelector , //
1061
+ sslContext , //
1062
+ providerConfig , //
1063
+ connectionsPool , //
1064
+ realm , //
1065
+ requestFilters , //
1066
+ responseFilters , //
1067
+ ioExceptionFilters , //
1068
+ requestCompressionLevel , //
1069
+ maxRequestRetry , //
1070
+ allowSslConnectionPool , //
1071
+ disableUrlEncodingForBoundedRequests , //
1072
+ removeQueryParamOnRedirect , //
1073
+ hostnameVerifier , //
1074
+ ioThreadMultiplier , //
1075
+ strict302Handling , //
1076
+ useRelativeURIsWithSSLProxies , //
1077
+ timeConverter , //
1078
+ acceptAnyCertificate );
1109
1079
}
1110
1080
}
1111
1081
}
1112
-
0 commit comments