List of usage examples for org.apache.http.impl.client HttpClientBuilder setProxy
public final HttpClientBuilder setProxy(final HttpHost proxy)
From source file:org.sonatype.spice.zapper.client.hc4.Hc4ClientBuilder.java
public Hc4Client build() { final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", SSLConnectionSocketFactory.getSystemSocketFactory()).build(); final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry); cm.setMaxTotal(200);/* w w w .j a v a2 s. com*/ cm.setDefaultMaxPerRoute(parameters.getMaximumTrackCount()); final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(cm) .setUserAgent("Zapper/1.0-HC4"); if (proxyServer != null) { httpClientBuilder.setProxy(proxyServer); } if (credentialsProvider != null) { httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); } return new Hc4Client(parameters, remoteUrl, httpClientBuilder.build(), preemptiveAuth ? credentialsProvider : null); }
From source file:com.bosch.iot.things.tutorial.ui.ProxyServlet.java
/** * Create http client/* www . j a v a2 s .c o m*/ */ private synchronized CloseableHttpClient getHttpClient() { if (httpClient == null) { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (props.getProperty("proxyHost") != null) { httpClientBuilder.setProxy(new HttpHost(props.getProperty("proxyHost"), Integer.parseInt(props.getProperty("proxyPort")))); } if (props.getProperty("proxyUser") != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost), new UsernamePasswordCredentials( props.getProperty("proxyUser"), props.getProperty("proxyPwd"))); httpClientBuilder.setDefaultCredentialsProvider(credsProvider); } httpClient = httpClientBuilder.build(); } return httpClient; }
From source file:org.mitre.stixwebtools.services.TaxiiService.java
/** * Creates a new HttpClient which is needed to make requests from a taxii server. * // w w w . ja va2 s . co m * @param proxyUrl * @param proxyPort * @return */ public HttpClient getTaxiiClient(String proxyUrl, int proxyPort) { //We have to make our own CloseableHttpClient so we can use a proxy HttpClientBuilder clientBuilder = HttpClientBuilder.create(); clientBuilder.useSystemProperties(); clientBuilder.setProxy(new HttpHost(proxyUrl, proxyPort)); CloseableHttpClient client = clientBuilder.build(); HttpClient httpClient = new HttpClient(client); return httpClient; }
From source file:com.logsniffer.settings.http.HttpSettings.java
/** * Creates a {@link HttpClientBuilder} considering current settings. * /*from w ww .j ava 2s . c om*/ * @return a {@link HttpClientBuilder} considering current settings. */ public HttpClientBuilder createHttpClientBuilder() { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (getHttpProxy() != null && StringUtils.isNotBlank(getHttpProxy().getHost())) { httpClientBuilder = httpClientBuilder.setProxy( new HttpHost(getHttpProxy().getHost(), getHttpProxy().getPort(), getHttpProxy().getSchema())); if (StringUtils.isNotBlank(getHttpProxy().getUser())) { Credentials credentials = new UsernamePasswordCredentials(getHttpProxy().getUser(), getHttpProxy().getPassword()); AuthScope authScope = new AuthScope(getHttpProxy().getHost(), getHttpProxy().getPort()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(authScope, credentials); httpClientBuilder = httpClientBuilder.setDefaultCredentialsProvider(credsProvider); httpClientBuilder.useSystemProperties(); } } return httpClientBuilder; }
From source file:de.tsystems.mms.apm.performancesignature.viewer.rest.model.CustomJenkinsHttpClient.java
private static HttpClientBuilder createHttpClientBuilder(final boolean verifyCertificate, final CustomProxy customProxy) { HttpClientBuilder httpClientBuilder = HttpClients.custom(); httpClientBuilder.useSystemProperties(); if (!verifyCertificate) { SSLContextBuilder builder = new SSLContextBuilder(); try {/* w w w . jav a 2 s . co m*/ builder.loadTrustMaterial(null, new TrustStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }); httpClientBuilder.setSSLSocketFactory(new SSLConnectionSocketFactory(builder.build())); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) { LOGGER.severe(ExceptionUtils.getFullStackTrace(e)); } } if (customProxy != null) { Jenkins jenkins = PerfSigUIUtils.getInstance(); if (customProxy.isUseJenkinsProxy() && jenkins.proxy != null) { final ProxyConfiguration proxyConfiguration = jenkins.proxy; if (StringUtils.isNotBlank(proxyConfiguration.name) && proxyConfiguration.port > 0) { httpClientBuilder.setProxy(new HttpHost(proxyConfiguration.name, proxyConfiguration.port)); if (StringUtils.isNotBlank(proxyConfiguration.getUserName())) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials( proxyConfiguration.getUserName(), proxyConfiguration.getUserName()); credsProvider.setCredentials( new AuthScope(proxyConfiguration.name, proxyConfiguration.port), usernamePasswordCredentials); httpClientBuilder.setDefaultCredentialsProvider(credsProvider); httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } } } else { httpClientBuilder.setProxy(new HttpHost(customProxy.getProxyServer(), customProxy.getProxyPort())); if (StringUtils.isNotBlank(customProxy.getProxyUser()) && StringUtils.isNotBlank(customProxy.getProxyPassword())) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); UsernamePasswordCredentials usernamePasswordCredentials = new UsernamePasswordCredentials( customProxy.getProxyUser(), customProxy.getProxyPassword()); credsProvider.setCredentials( new AuthScope(customProxy.getProxyServer(), customProxy.getProxyPort()), usernamePasswordCredentials); httpClientBuilder.setDefaultCredentialsProvider(credsProvider); httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); } } } return httpClientBuilder; }
From source file:com.bosch.cr.integration.helloworld.ProxyServlet.java
/** * Create http client//from w w w.ja v a 2s .c o m */ private synchronized CloseableHttpClient getHttpClient() { if (httpClient == null) { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (props.getProperty("http.proxyHost") != null) { httpClientBuilder.setProxy(new HttpHost(props.getProperty("http.proxyHost"), Integer.parseInt(props.getProperty("http.proxyPort")))); } if (props.getProperty("http.proxyUser") != null) { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(targetHost), new UsernamePasswordCredentials( props.getProperty("http.proxyUser"), props.getProperty("http.proxyPwd"))); httpClientBuilder.setDefaultCredentialsProvider(credsProvider); } httpClient = httpClientBuilder.build(); } return httpClient; }
From source file:com.cisco.cta.taxii.adapter.httpclient.HttpClientFactory.java
public HttpClient create() { HttpClientBuilder clientBuilder = HttpClientBuilder.create(); if (proxySettings.getUrl() != null) { URL proxyUrl = proxySettings.getUrl(); HttpHost proxyHost = new HttpHost(proxyUrl.getHost(), proxyUrl.getPort(), proxyUrl.getProtocol()); clientBuilder.setProxy(proxyHost); }//from w ww .ja v a2 s . c o m return clientBuilder.build(); }
From source file:com.googlesource.gerrit.plugins.github.oauth.PooledHttpClientProvider.java
@Override public HttpClient get() { HttpClientBuilder builder = HttpClientBuilder.create().setMaxConnPerRoute(maxConnectionPerRoute) .setMaxConnTotal(maxTotalConnection); if (proxy.getProxyUrl() != null) { URL url = proxy.getProxyUrl(); builder.setProxy(new HttpHost(url.getHost(), url.getPort())); if (!Strings.isNullOrEmpty(proxy.getUsername()) && !Strings.isNullOrEmpty(proxy.getPassword())) { UsernamePasswordCredentials creds = new UsernamePasswordCredentials(proxy.getUsername(), proxy.getPassword()); CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(url.getHost(), url.getPort()), creds); builder.setDefaultCredentialsProvider(credsProvider); builder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); }//ww w .j a v a 2s . co m } return builder.build(); }
From source file:io.github.bonigarcia.wdm.WdmHttpClient.java
private WdmHttpClient(String proxyUrl, String proxyUser, String proxyPass) { HttpHost proxyHost = createProxyHttpHost(proxyUrl); HttpClientBuilder builder = HttpClientBuilder.create(); if (proxyHost != null) { builder.setProxy(proxyHost); BasicCredentialsProvider credentialsProvider = createBasicCredentialsProvider(proxyUrl, proxyUser, proxyPass, proxyHost);/*from w w w .j av a2 s . com*/ builder.setDefaultCredentialsProvider(credentialsProvider); } this.httpClient = builder.build(); }