clientBuilder.setConnectionTimeout( data.realConnectionTimeout ); clientBuilder.setSocketTimeout( data.realSocketTimeout ); clientBuilder.setCredentials( data.realHttpLogin, data.realHttpPassword ); clientBuilder.setProxy( data.realProxyHost, data.realProxyPort ); CloseableHttpClient httpClient = clientBuilder.build();
if ( StringUtils.isNotBlank( proxyHostname ) && StringUtils.isNotBlank( proxyPort ) ) { int port = Integer.parseInt( this.proxyPort ); httpClientBuilder.setProxy( proxyHostname, port ); httpClientBuilder.setCredentials( username, password, authScope ); context = HttpClientUtil.createPreemptiveBasicAuthentication( tempURL.getHost(), tempURL.getPort(), username, password ); HttpClient client = httpClientBuilder.build();
clientBuilder.setProxy( host, Integer.parseInt( port ) ). setSocketTimeout( PAGE_TIMEOUT ).setConnectionTimeout( CONNECTION_TIMEOUT ); String user = System.getProperty( "http.proxyUser" ); if ( StringUtils.isNotBlank( user ) ) { String password = System.getProperty( "http.proxyPassword" ); clientBuilder.setCredentials( user, password ); httpClient = clientBuilder.build();
/** * Returns an instance of an HttpClient. Only one is created per ConnectionServiceClient so all calls should be * made synchronously. * * @return The HTTP client to be used for web service calls */ public static HttpClient getClient( String userId, String password ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); if ( StringUtils.isNotEmpty( userId ) && StringUtils.isNotEmpty( password ) ) { clientBuilder.setCredentials( userId, password ); } return clientBuilder.build(); }
@VisibleForTesting HttpClient getHttpClient( String user, String password ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = httpClientManager.createBuilder(); clientBuilder.setCredentials( user, password ); return clientBuilder.build(); }
public static HttpClient getClient() { clientBuilder.setSocketTimeout( PAGE_TIMEOUT ).setConnectionTimeout( CONNECTION_TIMEOUT ); return clientBuilder.build(); }
@VisibleForTesting HttpClient createHttpClient( String user, String password ) { HttpClientManager.HttpClientBuilderFacade httpClientBuilder = httpClientManager.createBuilder(); // client.setTimeout(10000); // client.setConnectionTimeout(10000); if ( StringUtils.isNotBlank( user ) ) { httpClientBuilder.setCredentials( user, password ); } return httpClientBuilder.build(); }
clientBuilder.setConnectionTimeout( data.realConnectionTimeout ); clientBuilder.setSocketTimeout( data.realSocketTimeout ); clientBuilder.setCredentials( data.realHttpLogin, data.realHttpPassword ); clientBuilder.setProxy( data.realProxyHost, data.realProxyPort ); CloseableHttpClient httpClient = clientBuilder.build();
if ( !Utils.isEmpty( username ) ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); clientBuilder.setCredentials( username, password ); httpClient = clientBuilder.build(); } else { httpClient = HttpClientManager.getInstance().createDefaultClient();
private HttpClient getHttpClient( HttpClientContext context ) { HttpClientManager.HttpClientBuilderFacade clientBuilder = HttpClientManager.getInstance().createBuilder(); String login = environmentSubstitute( meta.getHttpLogin() ); if ( StringUtils.isNotBlank( login ) ) { clientBuilder.setCredentials( login, Encr.decryptPasswordOptionallyEncrypted( environmentSubstitute( meta.getHttpPassword() ) ) ); } int proxyPort = 0; if ( StringUtils.isNotBlank( meta.getProxyHost() ) ) { proxyPort = Const.toInt( environmentSubstitute( meta.getProxyPort() ), 8080 ); clientBuilder.setProxy( meta.getProxyHost(), proxyPort ); } CloseableHttpClient httpClient = clientBuilder.build(); if ( proxyPort != 0 ) { // Preemptive authentication HttpHost target = new HttpHost( meta.getProxyHost(), proxyPort, "http" ); // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local auth cache BasicScheme basicAuth = new BasicScheme(); authCache.put( target, basicAuth ); // Add AuthCache to the execution context context.setAuthCache( authCache ); } return httpClient; }
@Before public void setup() throws Exception { HttpClientManager.HttpClientBuilderFacade builder = mock( HttpClientManager.HttpClientBuilderFacade.class ); HttpClientManager manager = mock( HttpClientManager.class ); doReturn( builder ).when( manager ).createBuilder(); CloseableHttpClient client = mock( CloseableHttpClient.class ); doReturn( client ).when( builder ).build(); CloseableHttpResponse response = mock( CloseableHttpResponse.class ); doReturn( response ).when( client ).execute( any( HttpGet.class ) ); BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent( new ByteArrayInputStream( DATA.getBytes() ) ); doReturn( entity ).when( response ).getEntity(); mockStatic( HttpClientManager.class ); when( HttpClientManager.getInstance() ).thenReturn( manager ); setInternalState( data, "realUrl", "http://pentaho.com" ); setInternalState( data, "argnrs", new int[0] ); doReturn( false ).when( meta ).isUrlInField(); doReturn( "body" ).when( meta ).getFieldName(); doReturn( false ).when( log ).isDetailed(); doCallRealMethod().when( http ).callHttpService( any( RowMetaInterface.class ), any( Object[].class ) ); doReturn( HttpURLConnection.HTTP_OK ).when( http ).requestStatusCode( any( CloseableHttpResponse.class ) ); doReturn( new Header[0] ).when( http ).searchForHeaders( any( CloseableHttpResponse.class ) ); setInternalState( http, "log", log ); setInternalState( http, "data", data ); setInternalState( http, "meta", meta ); }
public HttpClientBuilderFacade setCredentials( String user, String password ) { return setCredentials( user, password, AuthScope.ANY ); }
public HttpClientBuilderFacade createBuilder() { return new HttpClientBuilderFacade(); }
public HttpClientBuilderFacade setProxy( String proxyHost, int proxyPort ) { setProxy( proxyHost, proxyPort, "http" ); return this; }