use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig 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.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project elasticsearch-analysis-ik by medcl.
the class Dictionary method getRemoteWords.
/**
* 从远程服务器上下载自定义词条
*/
private static List<String> getRemoteWords(String location) {
List<String> buffer = new ArrayList<String>();
RequestConfig rc = RequestConfig.custom().setConnectionRequestTimeout(10 * 1000).setConnectTimeout(10 * 1000).setSocketTimeout(60 * 1000).build();
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response;
BufferedReader in;
HttpGet get = new HttpGet(location);
get.setConfig(rc);
try {
response = httpclient.execute(get);
if (response.getStatusLine().getStatusCode() == 200) {
String charset = "UTF-8";
// 获取编码,默认为utf-8
if (response.getEntity().getContentType().getValue().contains("charset=")) {
String contentType = response.getEntity().getContentType().getValue();
charset = contentType.substring(contentType.lastIndexOf("=") + 1);
}
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), charset));
String line;
while ((line = in.readLine()) != null) {
buffer.add(line);
}
in.close();
response.close();
return buffer;
}
response.close();
} catch (ClientProtocolException e) {
logger.error("getRemoteWords {} error", e, location);
} catch (IllegalStateException e) {
logger.error("getRemoteWords {} error", e, location);
} catch (IOException e) {
logger.error("getRemoteWords {} error", e, location);
}
return buffer;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project jersey by jersey.
the class ApacheConnector method getUriHttpRequest.
private HttpUriRequest getUriHttpRequest(final ClientRequest clientRequest) {
final RequestConfig.Builder requestConfigBuilder = RequestConfig.copy(requestConfig);
final int connectTimeout = clientRequest.resolveProperty(ClientProperties.CONNECT_TIMEOUT, -1);
final int socketTimeout = clientRequest.resolveProperty(ClientProperties.READ_TIMEOUT, -1);
if (connectTimeout >= 0) {
requestConfigBuilder.setConnectTimeout(connectTimeout);
}
if (socketTimeout >= 0) {
requestConfigBuilder.setSocketTimeout(socketTimeout);
}
final Boolean redirectsEnabled = clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, requestConfig.isRedirectsEnabled());
requestConfigBuilder.setRedirectsEnabled(redirectsEnabled);
final Boolean bufferingEnabled = clientRequest.resolveProperty(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.class) == RequestEntityProcessing.BUFFERED;
final HttpEntity entity = getHttpEntity(clientRequest, bufferingEnabled);
return RequestBuilder.create(clientRequest.getMethod()).setUri(clientRequest.getUri()).setConfig(requestConfigBuilder.build()).setEntity(entity).build();
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project jersey by jersey.
the class DisableContentEncodingTest method testEnabledByRequestConfig.
@Test
public void testEnabledByRequestConfig() {
ClientConfig cc = new ClientConfig(GZipEncoder.class);
final RequestConfig requestConfig = RequestConfig.custom().setContentCompressionEnabled(true).build();
cc.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
String enc = r.request().get().readEntity(String.class);
assertEquals("gzip,deflate", enc);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project DataX by alibaba.
the class RetryUtilTest method testRetryAsync3.
//@Test
@Ignore
public void testRetryAsync3() throws Exception {
final int TIME_OUT = 30000;
ThreadPoolExecutor executor = RetryUtil.createThreadPoolExecutor();
String res = RetryUtil.asyncExecuteWithRetry(new Callable<String>() {
@Override
public String call() throws Exception {
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(TIME_OUT).setConnectTimeout(TIME_OUT).setConnectionRequestTimeout(TIME_OUT).setStaleConnectionCheckEnabled(true).build();
HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(10).setMaxConnPerRoute(10).setDefaultRequestConfig(requestConfig).build();
HttpGet httpGet = new HttpGet();
httpGet.setURI(new URI("http://0.0.0.0:8080/test"));
httpClient.execute(httpGet);
return OK;
}
}, 3, 1000L, false, 6000L, executor);
Assert.assertEquals(res, OK);
// Assert.assertEquals(RetryUtil.EXECUTOR.getActiveCount(), 0);
}
Aggregations