List of usage examples for org.apache.http.impl.client HttpClientBuilder build
public CloseableHttpClient build()
From source file:uk.org.openeyes.oink.it.ITSupport.java
public static IGenericClient buildHapiClientForFacade(Properties proxyProps) { String proxyUri = (String) proxyProps.get("proxy.uri"); // Create a context and get the client factory so it can be configured FhirContext ctx = new FhirContext(); IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory(); // Create an HTTP Client Builder HttpClientBuilder builder = HttpClientBuilder.create(); // This interceptor adds HTTP username/password to every request String username = (String) proxyProps.get("proxy.username"); String password = (String) proxyProps.get("proxy.password"); builder.addInterceptorFirst(new HttpBasicAuthInterceptor(username, password)); builder.addInterceptorFirst(new HttpRequestInterceptor() { @Override/*from w w w .j av a 2 s .com*/ public void process(HttpRequest req, HttpContext context) throws HttpException, IOException { req.addHeader("Accept", "application/json+fhir; charset=UTF-8"); } }); // Use the new HTTP client builder clientFactory.setHttpClient(builder.build()); IGenericClient client = clientFactory.newGenericClient("http://" + proxyUri); return client; }
From source file:uk.org.openeyes.oink.it.ITSupport.java
public static IGenericClient buildHapiClientForProxy(Properties proxyProps) { // See if Patient exists String proxyUri = (String) proxyProps.get("proxy.uri"); // Create a context and get the client factory so it can be configured FhirContext ctx = new FhirContext(); IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory(); // Create an HTTP Client Builder HttpClientBuilder builder = HttpClientBuilder.create(); // This interceptor adds HTTP username/password to every request String username = (String) proxyProps.get("proxy.username"); String password = (String) proxyProps.get("proxy.password"); builder.addInterceptorFirst(new HttpBasicAuthInterceptor(username, password)); builder.addInterceptorFirst(new HttpRequestInterceptor() { @Override/*from w w w. ja va 2 s.c o m*/ public void process(HttpRequest req, HttpContext context) throws HttpException, IOException { req.addHeader("Accept", "application/json+fhir; charset=UTF-8"); } }); // Use the new HTTP client builder clientFactory.setHttpClient(builder.build()); IGenericClient client = clientFactory.newGenericClient("http://" + proxyUri); return client; }
From source file:com.liferay.sync.engine.lan.session.LanSession.java
private static HttpClient _createHttpClient(int connectTimeout, int maxPerRoute, int maxTotal, int socketTimeout) { RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder.create(); try {//from www . j a va2s .c om registryBuilder.register("https", _getSSLSocketFactory()); } catch (Exception e) { _logger.error(e.getMessage(), e); } PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager( registryBuilder.build()); connectionManager.setDefaultMaxPerRoute(maxPerRoute); connectionManager.setMaxTotal(maxTotal); HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); RequestConfig.Builder builder = RequestConfig.custom(); builder.setConnectTimeout(connectTimeout); builder.setSocketTimeout(socketTimeout); httpClientBuilder.setDefaultRequestConfig(builder.build()); httpClientBuilder.setConnectionManager(connectionManager); return httpClientBuilder.build(); }
From source file:photosharing.api.ExecutorUtil.java
/** * helper method that returns an HTTPClient executor with credentials * available./*from ww w. ja v a 2 s . co m*/ * * Also enables the test case to connect to ANY SSL Certificate * valid/invalid * * @return {Executor} or Null if there is an issue */ public static Executor getExecutor() { Executor executor = null; /* * if using one of the environments without a trusted CA chain or * you are using Fiddler, you want to set TRUST=TRUE in appconfig.properties */ Configuration config = Configuration.getInstance(null); String sTrust = config.getValue(Configuration.TRUST); boolean trusted = Boolean.parseBoolean(sTrust); if (trusted) { try { HttpClientBuilder builder = HttpClients.custom(); // Setup the SSL Context to Trust Any SSL Certificate SSLContextBuilder sslBuilder = new SSLContextBuilder(); sslBuilder.loadTrustMaterial(null, new TrustStrategy() { /** * override for fiddler proxy */ public boolean isTrusted(X509Certificate[] certs, String host) throws CertificateException { return true; } }); SSLContext sslContext = sslBuilder.build(); builder.setHostnameVerifier(new AllowAllHostnameVerifier()); builder.setSslcontext(sslContext); CloseableHttpClient httpClient = builder.build(); executor = Executor.newInstance(httpClient); } catch (NoSuchAlgorithmException e) { logger.log(Level.SEVERE, "Issue with No Algorithm " + e.toString()); } catch (KeyStoreException e) { logger.log(Level.SEVERE, "Issue with KeyStore " + e.toString()); } catch (KeyManagementException e) { logger.log(Level.SEVERE, "Issue with KeyManagement " + e.toString()); } } return executor; }
From source file:org.springframework.security.kerberos.client.KerberosRestTemplate.java
/** * Builds the default instance of {@link HttpClient} having kerberos * support./*from ww w . j a va2 s .c o m*/ * * @return the http client with spneno auth scheme */ private static HttpClient buildHttpClient() { HttpClientBuilder builder = HttpClientBuilder.create(); Lookup<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build(); builder.setDefaultAuthSchemeRegistry(authSchemeRegistry); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(null, -1, null), credentials); builder.setDefaultCredentialsProvider(credentialsProvider); CloseableHttpClient httpClient = builder.build(); return httpClient; }
From source file:uk.org.openeyes.oink.it.multi.ITHl7v2ToOpenEyes.java
public static IGenericClient buildOpenEyesClient(Properties props) { String proxyUri = (String) props.get("openeyes.uri"); // Create a context and get the client factory so it can be configured FhirContext ctx = new FhirContext(); IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory(); // Create an HTTP Client Builder HttpClientBuilder builder = HttpClientBuilder.create(); // This interceptor adds HTTP username/password to every request String username = (String) props.get("openeyes.username"); String password = (String) props.get("openeyes.password"); builder.addInterceptorFirst(new HttpBasicAuthInterceptor(username, password)); builder.addInterceptorFirst(new HttpRequestInterceptor() { @Override//from w w w .j av a 2 s.com public void process(HttpRequest req, HttpContext context) throws HttpException, IOException { req.addHeader("Accept", "application/json+fhir; charset=UTF-8"); } }); // Use the new HTTP client builder clientFactory.setHttpClient(builder.build()); IGenericClient client = clientFactory.newGenericClient("http://" + proxyUri); return client; }
From source file:com.github.tomakehurst.wiremock.http.HttpClientFactory.java
public static CloseableHttpClient createClient(int maxConnections, int timeoutMilliseconds, ProxySettings proxySettings, KeyStoreSettings trustStoreSettings) { HttpClientBuilder builder = HttpClientBuilder.create().disableAuthCaching().disableAutomaticRetries() .disableCookieManagement().disableRedirectHandling().disableContentCompression() .setMaxConnTotal(maxConnections) .setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(timeoutMilliseconds).build()) .useSystemProperties().setHostnameVerifier(new AllowAllHostnameVerifier()); if (proxySettings != NO_PROXY) { HttpHost proxyHost = new HttpHost(proxySettings.host(), proxySettings.port()); builder.setProxy(proxyHost);//from w w w . ja v a2 s. com } if (trustStoreSettings != NO_STORE) { builder.setSslcontext(buildSSLContextWithTrustStore(trustStoreSettings)); } else { builder.setSslcontext(buildAllowAnythingSSLContext()); } return builder.build(); }
From source file:com.vaushell.superpipes.tools.HTTPhelper.java
/** * Return all redirected URLs.//from ww w .java2 s . co m * * @param builder Http client builder * @param source Source URI * @return a list of redirected URLs * @throws IOException */ public static List<URI> getRedirected(final HttpClientBuilder builder, final URI source) throws IOException { if (builder == null || source == null) { throw new IllegalArgumentException(); } final List<URI> uris = new ArrayList<>(); builder.setRedirectStrategy(new DefaultRedirectStrategy() { @Override public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) throws ProtocolException { final HttpUriRequest r = super.getRedirect(request, response, context); uris.add(r.getURI()); return r; } }).build(); try (final CloseableHttpClient client = builder.build()) { final HttpGet get = new HttpGet(source); client.execute(get); get.abort(); } return uris; }
From source file:io.wcm.caravan.commons.httpclient.impl.HttpClientItem.java
private static CloseableHttpClient buildHttpClient(HttpClientConfig config, PoolingHttpClientConnectionManager connectionManager, CredentialsProvider credentialsProvider) { // prepare HTTPClient builder HttpClientBuilder httpClientBuilder = HttpClientBuilder.create().setConnectionManager(connectionManager); // timeout settings httpClientBuilder.setDefaultRequestConfig(RequestConfig.custom() .setConnectTimeout(config.getConnectTimeout()).setSocketTimeout(config.getSocketTimeout()).build()); httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); // optional proxy support if (StringUtils.isNotEmpty(config.getProxyHost())) { httpClientBuilder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort())); // optional proxy authentication if (StringUtils.isNotEmpty(config.getProxyUser())) { httpClientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy()); }/*from ww w .j ava 2s.c om*/ } return httpClientBuilder.build(); }
From source file:com.themodernway.server.core.support.spring.network.CoreNativeHttpRequestFactory.java
public CoreNativeHttpRequestFactory(final HttpClientBuilder builder) { this(builder.build()); }