4040import java .util .Optional ;
4141import java .util .concurrent .ConcurrentHashMap ;
4242import javax .net .ssl .SSLContext ;
43+
44+ import org .apache .hadoop .conf .Configuration ;
45+ import org .apache .hadoop .hbase .HBaseConfiguration ;
46+ import org .apache .hadoop .hbase .rest .Constants ;
4347import org .apache .hadoop .security .authentication .client .AuthenticatedURL ;
4448import org .apache .hadoop .security .authentication .client .AuthenticationException ;
4549import org .apache .hadoop .security .authentication .client .KerberosAuthenticator ;
@@ -76,6 +80,7 @@ public class Client {
7680
7781 private HttpClient httpClient ;
7882 private Cluster cluster ;
83+ private Configuration conf ;
7984 private boolean sslEnabled ;
8085 private HttpResponse resp ;
8186 private HttpGet httpGet = null ;
@@ -93,16 +98,22 @@ public Client() {
9398 this (null );
9499 }
95100
96- private void initialize (Cluster cluster , boolean sslEnabled , Optional <KeyStore > trustStore ) {
101+ private void initialize (Cluster cluster , Configuration conf , boolean sslEnabled ,
102+ Optional <KeyStore > trustStore ) {
97103 this .cluster = cluster ;
104+ this .conf = conf ;
98105 this .sslEnabled = sslEnabled ;
99106 extraHeaders = new ConcurrentHashMap <>();
100107 String clspath = System .getProperty ("java.class.path" );
101108 LOG .debug ("classpath " + clspath );
102109 HttpClientBuilder httpClientBuilder = HttpClients .custom ();
103110
104- RequestConfig requestConfig = RequestConfig .custom ().
105- setConnectTimeout (2000 ).build ();
111+ int connTimeout = this .conf .getInt (Constants .REST_CLIENT_CONN_TIMEOUT ,
112+ Constants .DEFAULT_REST_CLIENT_CONN_TIMEOUT );
113+ int socketTimeout = this .conf .getInt (Constants .REST_CLIENT_SOCKET_TIMEOUT ,
114+ Constants .DEFAULT_REST_CLIENT_SOCKET_TIMEOUT );
115+ RequestConfig requestConfig = RequestConfig .custom ().setConnectTimeout (connTimeout )
116+ .setSocketTimeout (socketTimeout ).build ();
106117 httpClientBuilder .setDefaultRequestConfig (requestConfig );
107118
108119 // Since HBASE-25267 we don't use the deprecated DefaultHttpClient anymore.
@@ -138,7 +149,17 @@ public Client(Cluster cluster) {
138149 * @param sslEnabled enable SSL or not
139150 */
140151 public Client (Cluster cluster , boolean sslEnabled ) {
141- initialize (cluster , sslEnabled , Optional .empty ());
152+ initialize (cluster , HBaseConfiguration .create (), sslEnabled , Optional .empty ());
153+ }
154+
155+ /**
156+ * Constructor
157+ * @param cluster the cluster definition
158+ * @param conf Configuration
159+ * @param sslEnabled enable SSL or not
160+ */
161+ public Client (Cluster cluster , Configuration conf , boolean sslEnabled ) {
162+ initialize (cluster , conf , sslEnabled , Optional .empty ());
142163 }
143164
144165 /**
@@ -151,8 +172,23 @@ public Client(Cluster cluster, boolean sslEnabled) {
151172 *
152173 * @throws ClientTrustStoreInitializationException if the trust store file can not be loaded
153174 */
154- public Client (Cluster cluster , String trustStorePath ,
155- Optional <String > trustStorePassword , Optional <String > trustStoreType ) {
175+ public Client (Cluster cluster , String trustStorePath , Optional <String > trustStorePassword ,
176+ Optional <String > trustStoreType ) {
177+ this (cluster , HBaseConfiguration .create (), trustStorePath , trustStorePassword , trustStoreType );
178+ }
179+
180+ /**
181+ * Constructor, allowing to define custom trust store (only for SSL connections)
182+ *
183+ * @param cluster the cluster definition
184+ * @param conf Configuration
185+ * @param trustStorePath custom trust store to use for SSL connections
186+ * @param trustStorePassword password to use for custom trust store
187+ * @param trustStoreType type of custom trust store
188+ * @throws ClientTrustStoreInitializationException if the trust store file can not be loaded
189+ */
190+ public Client (Cluster cluster , Configuration conf , String trustStorePath ,
191+ Optional <String > trustStorePassword , Optional <String > trustStoreType ) {
156192
157193 char [] password = trustStorePassword .map (String ::toCharArray ).orElse (null );
158194 String type = trustStoreType .orElse (KeyStore .getDefaultType ());
@@ -163,15 +199,15 @@ public Client(Cluster cluster, String trustStorePath,
163199 } catch (KeyStoreException e ) {
164200 throw new ClientTrustStoreInitializationException ("Invalid trust store type: " + type , e );
165201 }
166- try (InputStream inputStream =
167- new BufferedInputStream ( Files .newInputStream (new File (trustStorePath ).toPath ()))) {
202+ try (InputStream inputStream = new BufferedInputStream (
203+ Files .newInputStream (new File (trustStorePath ).toPath ()))) {
168204 trustStore .load (inputStream , password );
169205 } catch (CertificateException | NoSuchAlgorithmException | IOException e ) {
170206 throw new ClientTrustStoreInitializationException ("Trust store load error: " + trustStorePath ,
171207 e );
172208 }
173209
174- initialize (cluster , true , Optional .of (trustStore ));
210+ initialize (cluster , conf , true , Optional .of (trustStore ));
175211 }
176212
177213 /**
0 commit comments