use of org.apache.http.impl.client.HttpClientBuilder in project cryptomator by cryptomator.
the class WelcomeController method checkForUpdates.
private void checkForUpdates() {
checkForUpdatesStatus.setText(localization.getString("welcome.checkForUpdates.label.currentlyChecking"));
checkForUpdatesIndicator.setVisible(true);
asyncTaskService.asyncTaskOf(() -> {
RequestConfig requestConfig = //
RequestConfig.custom().setConnectTimeout(//
5000).setConnectionRequestTimeout(//
5000).setSocketTimeout(//
5000).build();
HttpClientBuilder httpClientBuilder = //
HttpClients.custom().disableCookieManagement().setDefaultRequestConfig(//
requestConfig).setUserAgent("Cryptomator VersionChecker/" + ApplicationVersion.orElse("SNAPSHOT"));
LOG.debug("Checking for updates...");
try (CloseableHttpClient client = httpClientBuilder.build()) {
HttpGet request = new HttpGet("https://cryptomator.org/downloads/latestVersion.json");
try (CloseableHttpResponse response = client.execute(request)) {
if (response.getStatusLine().getStatusCode() == 200 && response.getEntity() != null) {
try (InputStream in = response.getEntity().getContent()) {
Gson gson = new GsonBuilder().setLenient().create();
Reader utf8Reader = new InputStreamReader(in, StandardCharsets.UTF_8);
Map<String, String> map = gson.fromJson(utf8Reader, new TypeToken<Map<String, String>>() {
}.getType());
if (map != null) {
this.compareVersions(map);
}
}
}
}
}
}).andFinally(() -> {
checkForUpdatesStatus.setText("");
checkForUpdatesIndicator.setVisible(false);
}).run();
}
use of org.apache.http.impl.client.HttpClientBuilder in project camel by apache.
the class Olingo2Component method createOlingo2App.
private Olingo2AppWrapper createOlingo2App(Olingo2Configuration configuration) {
Object clientBuilder = configuration.getHttpAsyncClientBuilder();
if (clientBuilder == null) {
HttpAsyncClientBuilder asyncClientBuilder = HttpAsyncClientBuilder.create();
// apply simple configuration properties
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
requestConfigBuilder.setConnectTimeout(configuration.getConnectTimeout());
requestConfigBuilder.setSocketTimeout(configuration.getSocketTimeout());
final HttpHost proxy = configuration.getProxy();
if (proxy != null) {
requestConfigBuilder.setProxy(proxy);
}
// set default request config
asyncClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
SSLContextParameters sslContextParameters = configuration.getSslContextParameters();
if (sslContextParameters == null) {
// use defaults if not specified
sslContextParameters = new SSLContextParameters();
}
try {
asyncClientBuilder.setSSLContext(sslContextParameters.createSSLContext(getCamelContext()));
} catch (GeneralSecurityException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
} catch (IOException e) {
throw ObjectHelper.wrapRuntimeCamelException(e);
}
}
Olingo2AppImpl olingo2App;
if (clientBuilder == null || clientBuilder instanceof HttpAsyncClientBuilder) {
olingo2App = new Olingo2AppImpl(configuration.getServiceUri(), (HttpAsyncClientBuilder) clientBuilder);
} else {
olingo2App = new Olingo2AppImpl(configuration.getServiceUri(), (HttpClientBuilder) clientBuilder);
}
apiProxy = new Olingo2AppWrapper(olingo2App);
apiProxy.getOlingo2App().setContentType(configuration.getContentType());
apiProxy.getOlingo2App().setHttpHeaders(configuration.getHttpHeaders());
return apiProxy;
}
use of org.apache.http.impl.client.HttpClientBuilder in project google-analytics-java by brsanthu.
the class GoogleAnalyticsThreadFactory method createHttpClient.
protected CloseableHttpClient createHttpClient(GoogleAnalyticsConfig config) {
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));
HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connManager);
if (isNotEmpty(config.getUserAgent())) {
builder.setUserAgent(config.getUserAgent());
}
if (isNotEmpty(config.getProxyHost())) {
builder.setProxy(new HttpHost(config.getProxyHost(), config.getProxyPort()));
if (isNotEmpty(config.getProxyUserName())) {
BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()), new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
builder.setDefaultCredentialsProvider(credentialsProvider);
}
}
return builder.build();
}
use of org.apache.http.impl.client.HttpClientBuilder in project opennms by OpenNMS.
the class HttpClientWrapper method getClient.
public CloseableHttpClient getClient() {
if (m_httpClient == null) {
final HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
final RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (!m_reuseConnections) {
httpClientBuilder.setConnectionReuseStrategy(new NoConnectionReuseStrategy());
}
if (m_usePreemptiveAuth) {
enablePreemptiveAuth(httpClientBuilder);
}
if (m_useSystemProxySettings) {
httpClientBuilder.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()));
}
if (!isEmpty(m_cookieSpec)) {
requestConfigBuilder.setCookieSpec(m_cookieSpec);
}
if (m_cookieStore != null) {
httpClientBuilder.setDefaultCookieStore(m_cookieStore);
}
if (m_username != null) {
setCredentials(httpClientBuilder, m_username, m_password);
}
if (m_socketTimeout != null) {
requestConfigBuilder.setSocketTimeout(m_socketTimeout);
}
if (m_connectionTimeout != null) {
requestConfigBuilder.setConnectTimeout(m_connectionTimeout);
}
if (m_retries != null) {
httpClientBuilder.setRetryHandler(new HttpRequestRetryOnExceptionHandler(m_retries, false));
}
if (m_sslContext.size() != 0) {
configureSSLContext(httpClientBuilder);
}
for (final HttpRequestInterceptor interceptor : m_requestInterceptors) {
httpClientBuilder.addInterceptorLast(interceptor);
}
for (final HttpResponseInterceptor interceptor : m_responseInterceptors) {
httpClientBuilder.addInterceptorLast(interceptor);
}
if (m_useLaxRedirect) {
httpClientBuilder.setRedirectStrategy(new LaxRedirectStrategy());
}
httpClientBuilder.setDefaultRequestConfig(requestConfigBuilder.build());
m_httpClient = httpClientBuilder.build();
}
return m_httpClient;
}
use of org.apache.http.impl.client.HttpClientBuilder in project Xponents by OpenSextant.
the class SharepointClient method getClient.
/**
* Sharepoint requires NTLM. This client requires a non-null user/passwd/domain.
*
*/
@Override
public HttpClient getClient() {
if (currentConn != null) {
return currentConn;
}
HttpClientBuilder clientHelper = HttpClientBuilder.create();
if (proxyHost != null) {
clientHelper.setProxy(proxyHost);
}
RequestConfig globalConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY).build();
CredentialsProvider creds = new BasicCredentialsProvider();
creds.setCredentials(AuthScope.ANY, new NTCredentials(user, passwd, server, domain));
clientHelper.setDefaultCredentialsProvider(creds);
HttpClient httpClient = clientHelper.setDefaultRequestConfig(globalConfig).build();
return httpClient;
}
Aggregations