use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project webtools.sourceediting by eclipse.
the class HttpClientProvider method download.
private static File download(File file, URL url) {
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
OutputStream out = null;
file.getParentFile().mkdirs();
try {
HttpHost target = new HttpHost(url.getHost(), url.getPort(), url.getProtocol());
Builder builder = RequestConfig.custom();
HttpHost proxy = getProxy(target);
if (proxy != null) {
builder = builder.setProxy(proxy);
}
RequestConfig config = builder.build();
HttpGet request = new HttpGet(url.toURI());
request.setConfig(config);
response = httpclient.execute(target, request);
InputStream in = response.getEntity().getContent();
out = new BufferedOutputStream(new FileOutputStream(file));
copy(in, out);
return file;
} catch (Exception e) {
logWarning(e);
;
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
if (response != null) {
try {
response.close();
} catch (IOException e) {
}
}
try {
httpclient.close();
} catch (IOException e) {
}
}
return null;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project webdrivermanager by bonigarcia.
the class HttpClient method createHttpGet.
public HttpGet createHttpGet(URL url) {
HttpGet httpGet = new HttpGet(url.toString());
httpGet.addHeader("User-Agent", "Mozilla/5.0");
httpGet.addHeader("Connection", "keep-alive");
RequestConfig requestConfig = custom().setCookieSpec(STANDARD).setSocketTimeout(timeout).build();
httpGet.setConfig(requestConfig);
return httpGet;
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-framework by spring-projects.
the class HttpComponentsClientHttpRequestFactoryTests method retrieveRequestConfig.
private RequestConfig retrieveRequestConfig(HttpComponentsClientHttpRequestFactory factory) throws Exception {
URI uri = new URI(baseUrl + "/status/ok");
HttpComponentsClientHttpRequest request = (HttpComponentsClientHttpRequest) factory.createRequest(uri, HttpMethod.GET);
return (RequestConfig) request.getHttpContext().getAttribute(HttpClientContext.REQUEST_CONFIG);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project spring-framework by spring-projects.
the class HttpComponentsClientHttpRequestFactoryTests method assertCustomConfig.
@Test
public void assertCustomConfig() throws Exception {
HttpClient httpClient = HttpClientBuilder.create().build();
HttpComponentsClientHttpRequestFactory hrf = new HttpComponentsClientHttpRequestFactory(httpClient);
hrf.setConnectTimeout(1234);
hrf.setConnectionRequestTimeout(4321);
hrf.setReadTimeout(4567);
URI uri = new URI(baseUrl + "/status/ok");
HttpComponentsClientHttpRequest request = (HttpComponentsClientHttpRequest) hrf.createRequest(uri, HttpMethod.GET);
Object config = request.getHttpContext().getAttribute(HttpClientContext.REQUEST_CONFIG);
assertThat(config).as("Request config should be set").isNotNull();
assertThat(config).as("Wrong request config type " + config.getClass().getName()).isInstanceOf(RequestConfig.class);
RequestConfig requestConfig = (RequestConfig) config;
assertThat(requestConfig.getConnectTimeout()).as("Wrong custom connection timeout").isEqualTo(1234);
assertThat(requestConfig.getConnectionRequestTimeout()).as("Wrong custom connection request timeout").isEqualTo(4321);
assertThat(requestConfig.getSocketTimeout()).as("Wrong custom socket timeout").isEqualTo(4567);
}
use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project alluxio by Alluxio.
the class HttpUtils method post.
/**
* Uses the post method to send a url with arguments by http, this method can call RESTful Api.
*
* @param url the http url
* @param cookies the cookies to use in the request
* @param timeout milliseconds to wait for the server to respond before giving up
* @param processInputStream the response body stream processor
*/
public static void post(String url, String cookies, Integer timeout, IProcessInputStream processInputStream) throws IOException {
Preconditions.checkNotNull(timeout, "timeout");
Preconditions.checkNotNull(processInputStream, "processInputStream");
RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(timeout).setConnectTimeout(timeout).setSocketTimeout(timeout).build();
try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build()) {
HttpUriRequest req;
if (cookies.isEmpty()) {
req = RequestBuilder.post(url).build();
} else {
req = RequestBuilder.post(url).setHeader(HttpHeaders.COOKIE, cookies).build();
}
HttpResponse response = client.execute(req);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) {
InputStream inputStream = response.getEntity().getContent();
processInputStream.process(inputStream);
} else {
// Print the full content for debugging
if (LOG.isDebugEnabled()) {
String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.ISO_8859_1);
LOG.debug("Full content: {}", content);
}
throw new IOException(String.format("Failed to perform POST request: %s", response.getStatusLine()));
}
}
}
Aggregations