2626import java .net .URISyntaxException ;
2727import java .net .URL ;
2828import java .nio .file .Files ;
29+ import java .nio .file .Path ;
2930import java .security .GeneralSecurityException ;
3031import java .security .KeyManagementException ;
3132import java .security .KeyStore ;
@@ -256,7 +257,7 @@ public Client(Cluster cluster, Configuration conf, boolean sslEnabled,
256257 /**
257258 * Constructor, allowing to define custom trust store (only for SSL connections) This constructor
258259 * also enables sticky mode. This is a preferred constructor when not using BASIC or JWT
259- * authentication. Clients created by this will not use the old faulty load balancing logic.
260+ * authentication. Clients created by this will use the old faulty load balancing logic.
260261 * @param cluster the cluster definition
261262 * @param conf HBase/Hadoop Configuration
262263 * @param trustStorePath custom trust store to use for SSL connections
@@ -267,7 +268,7 @@ public Client(Cluster cluster, Configuration conf, boolean sslEnabled,
267268 public Client (Cluster cluster , Configuration conf , boolean sslEnabled , String trustStorePath ,
268269 Optional <String > trustStorePassword , Optional <String > trustStoreType ) {
269270 KeyStore trustStore = loadTruststore (trustStorePath , trustStorePassword , trustStoreType );
270- initialize (cluster , conf , true , false , Optional .of (trustStore ), Optional .empty (),
271+ initialize (cluster , conf , sslEnabled , false , Optional .of (trustStore ), Optional .empty (),
271272 Optional .empty (), Optional .empty ());
272273 }
273274
@@ -437,7 +438,6 @@ public HttpResponse executeURI(HttpUriRequest method, Header[] headers, String u
437438 throw new IOException (e );
438439 }
439440 if (stickyContext != null ) {
440- // We set the cookie twice, but it shouldn't be a problem
441441 resp = httpClient .execute (method , stickyContext );
442442 } else {
443443 resp = httpClient .execute (method );
@@ -513,18 +513,17 @@ private void negotiate(HttpUriRequest method, String uri)
513513
514514 private Configuration setupTrustStoreForHadoop (KeyStore trustStore )
515515 throws IOException , KeyStoreException , NoSuchAlgorithmException , CertificateException {
516- String tmpdir =
517- Files .createTempDirectory ("hbase_rest_client_truststore" ).toFile ().getAbsolutePath ();
518- String trustStoreLocation = tmpdir + File .separator + "truststore.jks" ;
516+ Path tmpDirPath = Files .createTempDirectory ("hbase_rest_client_truststore" );
517+ File trustStoreFile = tmpDirPath .resolve ("truststore.jks" ).toFile ();
519518 // Shouldn't be needed with the secure temp dir, but let's generate a password anyway
520519 String password = Double .toString (Math .random ());
521- try (FileOutputStream fos = new FileOutputStream (trustStoreLocation )) {
520+ try (FileOutputStream fos = new FileOutputStream (trustStoreFile )) {
522521 trustStore .store (fos , password .toCharArray ());
523522 }
524523
525524 Configuration sslConf = new Configuration ();
526525 // Type is the Java default, we use the same JVM to read this back
527- sslConf .set ("ssl.client.keystore.location" , trustStoreLocation );
526+ sslConf .set ("ssl.client.keystore.location" , trustStoreFile . getAbsolutePath () );
528527 sslConf .set ("ssl.client.keystore.password" , password );
529528 return sslConf ;
530529 }
0 commit comments