7171import org .apache .http .client .AuthCache ;
7272import org .apache .http .client .CredentialsProvider ;
7373import org .apache .http .client .HttpClient ;
74+ import org .apache .http .client .config .RequestConfig ;
7475import org .apache .http .client .methods .HttpDelete ;
7576import org .apache .http .client .methods .HttpGet ;
7677import org .apache .http .client .methods .HttpPost ;
@@ -173,6 +174,10 @@ public class HFCAClient {
173174
174175 private static final Config config = Config .getConfig (); // DO NOT REMOVE THIS IS NEEDED TO MAKE SURE WE FIRST LOAD CONFIG!!!
175176
177+ private static final int CONNECTION_REQUEST_TIMEOUT = config .getConnectionRequestTimeout ();
178+ private static final int CONNECT_TIMEOUT = config .getConnectTimeout ();
179+ private static final int SOCKET_TIMEOUT = config .getSocketTimeout ();
180+
176181 private static final Log logger = LogFactory .getLog (HFCAClient .class );
177182
178183 static final String FABRIC_CA_REQPROP = "caname" ;
@@ -1088,6 +1093,7 @@ String httpPost(String url, String body, UsernamePasswordCredentials credentials
10881093 HttpClient client = httpClientBuilder .build ();
10891094
10901095 HttpPost httpPost = new HttpPost (url );
1096+ httpPost .setConfig (getRequestConfig ());
10911097
10921098 AuthCache authCache = new BasicAuthCache ();
10931099
@@ -1142,6 +1148,7 @@ String httpPost(String url, String body, UsernamePasswordCredentials credentials
11421148 JsonObject httpPost (String url , String body , User registrar ) throws Exception {
11431149 String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), body );
11441150 HttpPost httpPost = new HttpPost (url );
1151+ httpPost .setConfig (getRequestConfig ());
11451152 logger .debug (format ("httpPost %s, body:%s, authHTTPCert: %s" , url , body , authHTTPCert ));
11461153
11471154 final HttpClientBuilder httpClientBuilder = HttpClientBuilder .create ();
@@ -1163,6 +1170,7 @@ JsonObject httpGet(String url, User registrar) throws Exception {
11631170 String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "" );
11641171 url = getURL (url );
11651172 HttpGet httpGet = new HttpGet (url );
1173+ httpGet .setConfig (getRequestConfig ());
11661174 logger .debug (format ("httpGet %s, authHTTPCert: %s" , url , authHTTPCert ));
11671175
11681176 final HttpClientBuilder httpClientBuilder = HttpClientBuilder .create ();
@@ -1182,6 +1190,7 @@ JsonObject httpGet(String url, User registrar) throws Exception {
11821190 JsonObject httpPut (String url , String body , User registrar ) throws Exception {
11831191 String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), body );
11841192 HttpPut httpPut = new HttpPut (url );
1193+ httpPut .setConfig (getRequestConfig ());
11851194 logger .debug (format ("httpPutt %s, body:%s, authHTTPCert: %s" , url , body , authHTTPCert ));
11861195
11871196 final HttpClientBuilder httpClientBuilder = HttpClientBuilder .create ();
@@ -1202,6 +1211,7 @@ JsonObject httpPut(String url, String body, User registrar) throws Exception {
12021211 JsonObject httpDelete (String url , User registrar ) throws Exception {
12031212 String authHTTPCert = getHTTPAuthCertificate (registrar .getEnrollment (), "" );
12041213 HttpDelete httpDelete = new HttpDelete (url );
1214+ httpDelete .setConfig (getRequestConfig ());
12051215 logger .debug (format ("httpPut %s, authHTTPCert: %s" , url , authHTTPCert ));
12061216
12071217 final HttpClientBuilder httpClientBuilder = HttpClientBuilder .create ();
@@ -1461,5 +1471,17 @@ String toJson(JsonObject toJsonFunc) {
14611471 return stringWriter .toString ();
14621472 }
14631473
1474+ private RequestConfig getRequestConfig () {
1475+
1476+ RequestConfig .Builder ret = RequestConfig .custom ();
1477+
1478+ ret .setConnectionRequestTimeout (CONNECTION_REQUEST_TIMEOUT );
1479+ ret .setConnectTimeout (CONNECT_TIMEOUT );
1480+ ret .setSocketTimeout (SOCKET_TIMEOUT );
1481+
1482+ return ret .build ();
1483+
1484+ }
1485+
14641486}
14651487
0 commit comments