final HttpHost target = HttpHost.create(crowdServer.toString()); final PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setDefaultMaxPerRoute(crowdProps.getHttpMaxConnections());
private RestClient getClient(ElasticsearchContainer container) { if (client == null) { final CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(ELASTICSEARCH_USERNAME, ELASTICSEARCH_PASSWORD)); client = RestClient.builder(HttpHost.create(container.getHttpHostAddress())) .setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)) .build(); } return client; }
private static RestClientBuilder buildRestClient(Elasticsearch settings) { List<HttpHost> hosts = new ArrayList<>(settings.getNodes().size()); settings.getNodes().forEach(node -> hosts.add(HttpHost.create(node.getDecodedUrl()))); RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()])); if (settings.getUsername() != null) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword())); builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); } return builder; }
private static RestClientBuilder buildRestClient(Elasticsearch settings) { List<HttpHost> hosts = new ArrayList<>(settings.getNodes().size()); settings.getNodes().forEach(node -> hosts.add(HttpHost.create(node.getDecodedUrl()))); RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()])); if (settings.getUsername() != null) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword())); builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); } return builder; }
private static RestClientBuilder buildRestClient(Elasticsearch settings) { List<HttpHost> hosts = new ArrayList<>(settings.getNodes().size()); settings.getNodes().forEach(node -> hosts.add(HttpHost.create(node.getDecodedUrl()))); RestClientBuilder builder = RestClient.builder(hosts.toArray(new HttpHost[hosts.size()])); if (settings.getUsername() != null) { CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword())); builder.setHttpClientConfigCallback(httpClientBuilder -> httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider)); } return builder; }
/** * @since 4.4 */ public Request viaProxy(final String proxy) { this.proxy = HttpHost.create(proxy); return this; }
public MailWebApi viaProxy(String proxy) { this.proxy = HttpHost.create(proxy); return this; }
AmazonInstanceTypeCachingAgent(String region, AccountCredentialsRepository accountCredentialsRepository, HttpClient httpClient) { this.region = region; this.accountCredentialsRepository = accountCredentialsRepository; pricingHost = HttpHost.create("https://pricing.us-east-1.amazonaws.com"); pricingUri = URI.create("/offers/v1.0/aws/AmazonEC2/current/" + region + "/index.json"); this.httpClient = httpClient; }
/** * @since 4.4 */ public Executor auth(final String host, final Credentials creds) { return auth(HttpHost.create(host), creds); }
/** * @since 4.4 */ public Executor authPreemptive(final String host) { return authPreemptive(HttpHost.create(host)); }
/** * @since 4.4 */ public Executor authPreemptiveProxy(final String proxy) { return authPreemptiveProxy(HttpHost.create(proxy)); }
public static void main(final String[] args) throws Exception { if (args.length < 1) { System.out.println("Usage: <hostname[:port]> [listener port]"); System.exit(1); } final HttpHost targetHost = HttpHost.create(args[0]); int port = 8080; if (args.length > 1) { port = Integer.parseInt(args[1]); } start(port); }
/** * Create new instance of {@code HttpDashboardProvider} for communication with Graphite instance with * specified host and connection parameters, without authentication. * @param graphiteHost host of target Graphite instance. Must be valid URL. * @param connectTimeout connection timeout in milliseconds. * @param readTimeout read timeout in milliseconds. */ public HttpDashboardProvider(String graphiteHost, int connectTimeout, int readTimeout) { notNull(graphiteHost, "'graphiteHost must be initialized."); isTrue(connectTimeout >= 0, "'connectTimeout must not be negative: ", connectTimeout); isTrue(readTimeout >= 0, "'readTimeout' must not be negative: ", readTimeout); this.client = createHttpClient(null, null, connectTimeout, readTimeout); this.host = HttpHost.create(graphiteHost); }
public static HttpHost createHttpHost(String s, int defaultPort, boolean secure) { final HttpHost host = HttpHost.create(s); if ("https".equals(host.getSchemeName()) && !secure) { throw new ConfigException("Elasticsearch host URL " + host + " uses https; must set elasticsearch 'secureConnection' config key to true."); } return host.getPort() != -1 ? host : new HttpHost(host.getHostName(), defaultPort, secure ? "https" : "http"); }
static ServerUris fromStrings(List<String> serverUrisStrings) { HttpHost[] hosts = new HttpHost[serverUrisStrings.size()]; boolean anyHostRequiresSSL = false; for ( int i = 0 ; i < serverUrisStrings.size() ; ++i ) { HttpHost host = HttpHost.create( serverUrisStrings.get( i ) ); hosts[i] = host; String scheme = host.getSchemeName(); if ( "https".equals( scheme ) ) { anyHostRequiresSSL = true; } } return new ServerUris( hosts, anyHostRequiresSSL ); }
static ServerUris fromStrings(List<String> serverUrisStrings) { HttpHost[] hosts = new HttpHost[serverUrisStrings.size()]; boolean anyHostRequiresSSL = false; for ( int i = 0 ; i < serverUrisStrings.size() ; ++i ) { HttpHost host = HttpHost.create( serverUrisStrings.get( i ) ); hosts[i] = host; String scheme = host.getSchemeName(); if ( "https".equals( scheme ) ) { anyHostRequiresSSL = true; } } return new ServerUris( hosts, anyHostRequiresSSL ); }
static ServerUris fromString(String serverUrisString) { String[] serverUris = serverUrisString.trim().split( "\\s" ); HttpHost[] hosts = new HttpHost[serverUris.length]; boolean anyHostRequiresSSL = false; for ( int i = 0 ; i < serverUris.length ; ++i ) { HttpHost host = HttpHost.create( serverUris[i] ); hosts[i] = host; String scheme = host.getSchemeName(); if ( "https".equals( scheme ) ) { anyHostRequiresSSL = true; } } return new ServerUris( hosts, anyHostRequiresSSL ); }
private static HttpClientBuilder handleAuthMethod (final CommandLine commandLine, HttpClientBuilder executor, final String hostname) { if (commandLine.getOptionValue (Arguments.AUTH.getOpt ()) != null) { final String [] authValue = commandLine.getOptionValue (Arguments.AUTH.getOpt ()).split ("(?<!\\\\):"); if (commandLine.hasOption (Arguments.NTLM.getOpt ())) { final String [] userName = authValue [0].split ("\\\\"); final SystemDefaultCredentialsProvider systemDefaultCredentialsProvider = new SystemDefaultCredentialsProvider (); systemDefaultCredentialsProvider.setCredentials (AuthScope.ANY, new NTCredentials (userName [1], authValue [1], hostname, userName [0])); executor = executor.setDefaultCredentialsProvider (systemDefaultCredentialsProvider); } else { final BasicCredentialsProvider basicCredentialsProvider = new BasicCredentialsProvider (); basicCredentialsProvider.setCredentials (new AuthScope (HttpHost.create (URI.create (commandLine.getArgs () [0]).getHost ())), new UsernamePasswordCredentials (authValue [0], authValue.length > 1 ? authValue [1] : null)); executor = executor.setDefaultCredentialsProvider (basicCredentialsProvider); } } return executor; }
private RestHighLevelClient newRestEsHighLevelClient() { return new RestHighLevelClient(RestClient.builder( this.esConfigs .stream() .map(esConfig -> HttpHost.create(esConfig.getServer())) .toArray(HttpHost[]::new) )); }
public HttpHost getHttpHost() { return HttpHost.create( getProtocol() + "://" + getHost() + ":" + getPort() ); }