private CloseableHttpClient getClient ( ) { if ( this . closeableHttpClient != null ) { return this . closeableHttpClient ; } //Only accept self signed certificate if in Junit test case. String pathToFluidTrustStore = this . getPathToFluidSpecificTrustStore ( ) ; //Test mode... if ( IS_IN_JUNIT_TEST_MODE || pathToFluidTrustStore != null ) { SSLContextBuilder builder = new SSLContextBuilder ( ) ; try { //builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); if ( pathToFluidTrustStore == null ) { builder . loadTrustMaterial ( new SSLTrustAll ( ) ) ; } else { String password = this . getFluidSpecificTrustStorePassword ( ) ; if ( password == null ) { password = UtilGlobal . EMPTY ; } if ( IS_IN_JUNIT_TEST_MODE ) { builder . loadTrustMaterial ( new File ( pathToFluidTrustStore ) , password . toCharArray ( ) , new SSLTrustAll ( ) ) ; } else { builder . loadTrustMaterial ( new File ( pathToFluidTrustStore ) , password . toCharArray ( ) ) ; } } SSLContext sslContext = builder . build ( ) ; this . closeableHttpClient = HttpClients . custom ( ) . setSSLSocketFactory ( new SSLConnectionSocketFactory ( sslContext ) ) . build ( ) ; } catch ( NoSuchAlgorithmException e ) { //Changed for Java 1.6 compatibility... throw new FluidClientException ( "NoSuchAlgorithm: Unable to load self signed trust material. " + e . getMessage ( ) , e , FluidClientException . ErrorCode . CRYPTOGRAPHY ) ; } catch ( KeyManagementException e ) { throw new FluidClientException ( "KeyManagement: Unable to load self signed trust material. " + e . getMessage ( ) , e , FluidClientException . ErrorCode . CRYPTOGRAPHY ) ; } catch ( KeyStoreException e ) { throw new FluidClientException ( "KeyStore: Unable to load self signed trust material. " + e . getMessage ( ) , e , FluidClientException . ErrorCode . CRYPTOGRAPHY ) ; } catch ( CertificateException e ) { throw new FluidClientException ( "Certificate: Unable to load self signed trust material. " + e . getMessage ( ) , e , FluidClientException . ErrorCode . CRYPTOGRAPHY ) ; } catch ( IOException ioError ) { throw new FluidClientException ( "IOError: Unable to load self signed trust material. " + ioError . getMessage ( ) , ioError , FluidClientException . ErrorCode . CRYPTOGRAPHY ) ; } } else { //Default HTTP Client... this . closeableHttpClient = HttpClients . createDefault ( ) ; } return this . closeableHttpClient ; }
Creates a new Http client .