List of usage examples for org.apache.http.impl.client HttpClientBuilder build
public CloseableHttpClient build()
From source file:de.shadowhunt.subversion.internal.AbstractHelper.java
public HttpClient getHttpClient(final String username, final HttpRequestInterceptor... interceptors) { final HttpClientBuilder builder = HttpClientBuilder.create(); final CredentialsProvider cp = new BasicCredentialsProvider(); final Credentials credentials = new UsernamePasswordCredentials(username, PASSWORD); cp.setCredentials(AuthScope.ANY, credentials); builder.setDefaultCredentialsProvider(cp); for (HttpRequestInterceptor interceptor : interceptors) { builder.addInterceptorFirst(interceptor); }//from www . j av a2s .com builder.setRetryHandler(new SubversionRequestRetryHandler()); return builder.build(); }
From source file:se.skltp.adapterservices.druglogistics.dosdispensing.RetryComponent.java
private HttpClient setupHttpClient() { HttpClientBuilder httpClientBuilder = HttpClients.custom() .setRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); if (endpointAddress.toLowerCase().startsWith("https")) { httpClientBuilder = httpClientBuilder.setConnectionManager(setupSSLConnectionManager()); }//from ww w .ja v a 2 s .co m HttpClient httpclient = httpClientBuilder.build(); return httpclient; }
From source file:org.fcrepo.mint.HttpPidMinter.java
/** * Setup authentication in httpclient./* w w w . ja v a 2 s. c o m*/ * @return the setup of authentication **/ protected HttpClient buildClient() { HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties() .setConnectionManager(connManager); if (!isBlank(username) && !isBlank(password)) { final URI uri = URI.create(url); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); builder = builder.setDefaultCredentialsProvider(credsProvider); } return builder.build(); }
From source file:org.osgpfoundation.osgp.webdemoapp.infra.platform.SoapRequestHelper.java
/** * Creates a HttpComponentsMessageSender for communication with the * platform./*www.j a va2 s . c o m*/ * * @return HttpComponentsMessageSender */ private HttpComponentsMessageSender createHttpMessageSender() { final HttpComponentsMessageSender sender = new HttpComponentsMessageSender(); final HttpClientBuilder builder = HttpClients.custom(); builder.addInterceptorFirst(new ContentLengthHeaderRemoveInterceptor()); try { final SSLContext sslContext = new SSLContextBuilder() .loadKeyMaterial(this.keyStoreHelper.getKeyStore(), this.keyStoreHelper.getKeyStorePwAsChar()) .loadTrustMaterial(this.keyStoreHelper.getTrustStore()).build(); final SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(sslContext); builder.setSSLSocketFactory(sslConnectionFactory); sender.setHttpClient(builder.build()); } catch (KeyManagementException | UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) { e.printStackTrace(); } return sender; }
From source file:com.mirth.connect.client.core.ServerConnection.java
public ServerConnection(int timeout, String[] httpsProtocols, String[] httpsCipherSuites, boolean allowHTTP) { SSLContext sslContext = null; try {//from ww w .j a v a 2 s. c o m sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); } catch (Exception e) { logger.error("Unable to build SSL context.", e); } String[] enabledProtocols = MirthSSLUtil.getEnabledHttpsProtocols(httpsProtocols); String[] enabledCipherSuites = MirthSSLUtil.getEnabledHttpsCipherSuites(httpsCipherSuites); SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, enabledProtocols, enabledCipherSuites, NoopHostnameVerifier.INSTANCE); RegistryBuilder<ConnectionSocketFactory> builder = RegistryBuilder.<ConnectionSocketFactory>create() .register("https", sslConnectionSocketFactory); if (allowHTTP) { builder.register("http", PlainConnectionSocketFactory.getSocketFactory()); } Registry<ConnectionSocketFactory> socketFactoryRegistry = builder.build(); PoolingHttpClientConnectionManager httpClientConnectionManager = new PoolingHttpClientConnectionManager( socketFactoryRegistry); httpClientConnectionManager.setDefaultMaxPerRoute(5); httpClientConnectionManager.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(timeout).build()); // MIRTH-3962: The stale connection settings has been deprecated, and this is recommended instead httpClientConnectionManager.setValidateAfterInactivity(5000); HttpClientBuilder clientBuilder = HttpClients.custom().setConnectionManager(httpClientConnectionManager); HttpUtil.configureClientBuilder(clientBuilder); client = clientBuilder.build(); requestConfig = RequestConfig.custom().setConnectTimeout(CONNECT_TIMEOUT) .setConnectionRequestTimeout(CONNECT_TIMEOUT).setSocketTimeout(timeout).build(); }
From source file:br.com.autonomiccs.apacheCloudStack.client.ApacheCloudStackClient.java
/** * It creates an {@link CloseableHttpClient} object. * If {@link #validateServerHttpsCertificate} indicates that we should not validate HTTPS server certificate, we use an insecure SSL factory; the insecure factory is created using {@link #createInsecureSslFactory()}. *//*from w w w . ja v a 2 s. c o m*/ protected CloseableHttpClient createHttpClient() { HttpClientBuilder httpClientBuilder = HttpClientBuilder.create(); if (!validateServerHttpsCertificate) { SSLConnectionSocketFactory sslsf = createInsecureSslFactory(); httpClientBuilder.setSSLSocketFactory(sslsf); } return httpClientBuilder.build(); }
From source file:org.fcrepo.kernel.impl.identifiers.HttpPidMinter.java
/** * Setup authentication in httpclient.// w ww .ja v a2 s . c o m **/ protected HttpClient buildClient() { HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties() .setConnectionManager(new PoolingHttpClientConnectionManager()); if (!isBlank(username) && !isBlank(password)) { final URI uri = URI.create(url); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(uri.getHost(), uri.getPort()), new UsernamePasswordCredentials(username, password)); builder = builder.setDefaultCredentialsProvider(credsProvider); } return builder.build(); }
From source file:org.apache.manifoldcf.agents.output.opensearchserver.OpenSearchServerConnector.java
protected HttpClient getSession() throws ManifoldCFException { if (client == null) { connectionManager = new PoolingHttpClientConnectionManager(); final int executorTimeout = 300000; final int socketTimeout = 60000; final int connectionTimeout = 60000; RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true) .setSocketTimeout(socketTimeout).setStaleConnectionCheckEnabled(true) .setExpectContinueEnabled(true).setConnectTimeout(connectionTimeout) .setConnectionRequestTimeout(socketTimeout); HttpClientBuilder clientBuilder = HttpClients.custom().setConnectionManager(connectionManager) .setMaxConnTotal(1).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build()) .setRequestExecutor(new HttpRequestExecutor(executorTimeout)).setDefaultSocketConfig( SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build()); client = clientBuilder.build(); }/*from ww w. ja va 2s . co m*/ expirationTime = System.currentTimeMillis() + EXPIRATION_INTERVAL; return client; }
From source file:org.openestate.is24.restapi.hc43.HttpComponents43Client.java
/** * Use a default {@link HttpClient} for HTTP traffic. * * @param timeout/*from w w w . ja v a2s. co m*/ * timeout for HTTP communication (in milliseconds) */ public void setDefaultHttpClient(int timeout) { if (timeout < 0) timeout = 0; //HttpParams params = new BasicHttpParams(); //HttpProtocolParams.setVersion( params, HttpVersion.HTTP_1_1 ); //HttpProtocolParams.setContentCharset( params, getEncoding() ); //HttpProtocolParams.setUseExpectContinue( params, true ); //HttpConnectionParams.setConnectionTimeout( params, timeout ); //HttpConnectionParams.setSoTimeout( params, timeout ); // Register the "http" and "https" protocol schemes, they are // required by the default operator to look up socket factories. //SchemeRegistry supportedSchemes = new SchemeRegistry(); //supportedSchemes.register( new Scheme( "http", PlainSocketFactory.getSocketFactory(), 80 ) ); //supportedSchemes.register( new Scheme( "https", SSLSocketFactory.getSocketFactory(), 443 ) ); // create http-client //setHttpClient( new DefaultHttpClient( new ThreadSafeClientConnManager( params, supportedSchemes ), params ) ); //setHttpClient( new DefaultHttpClient( params ) ); HttpClientBuilder b = HttpClientBuilder.create(); b.setDefaultRequestConfig(RequestConfig.custom().setConnectTimeout(timeout) .setConnectionRequestTimeout(timeout).setSocketTimeout(timeout).build()); //b.setDefaultSocketConfig( SocketConfig.custom() // .setSoTimeout( timeout ) // .build() ); setHttpClient(b.build()); }