Search in sources :

Example 11 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project intellij-community by JetBrains.

the class EduAdaptiveStepicConnector method setTimeout.

private static void setTimeout(HttpGet request) {
    final RequestConfig requestConfig = RequestConfig.custom().setConnectionRequestTimeout(CONNECTION_TIMEOUT).setConnectTimeout(CONNECTION_TIMEOUT).setSocketTimeout(CONNECTION_TIMEOUT).build();
    request.setConfig(requestConfig);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig)

Example 12 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project mastering-java by Kingminghuang.

the class HttpClientCrawler method testTimeout.

private static void testTimeout() throws IOException {
    int timeout = 15;
    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).setConnectionRequestTimeout(timeout * 1000).setProxy(new HttpHost(DEFAULT_PROXY, DEFAULT_PORT, DEFAULT_SCHEMA)).build();
    config(requestConfig);
    HttpGet httpGet = new HttpGet("http://www.google.com:80");
    HttpResponse response = client.execute(httpGet);
    System.out.println(response.getStatusLine().getStatusCode());
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 13 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project mastering-java by Kingminghuang.

the class HttpClientCrawler method testHardTimeout.

private static void testHardTimeout() throws IOException {
    int hardTimeout = 15;
    RequestConfig requestConfig = RequestConfig.custom().setProxy(new HttpHost(DEFAULT_PROXY, DEFAULT_PORT, DEFAULT_SCHEMA)).build();
    config(requestConfig);
    HttpGet httpGet = new HttpGet(EXAMPLE_URL);
    TimerTask task = new TimerTask() {

        @Override
        public void run() {
            if (httpGet != null) {
                httpGet.abort();
            }
        }
    };
    new Timer(true).schedule(task, hardTimeout * 1000);
    HttpResponse response = client.execute(httpGet);
    System.out.println(response.getStatusLine().getStatusCode());
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) TimerTask(java.util.TimerTask) Timer(java.util.Timer) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 14 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project mastering-java by Kingminghuang.

the class HttpClientCrawler method testStatusCode.

private static void testStatusCode() throws IOException {
    RequestConfig requestConfig = RequestConfig.custom().setProxy(new HttpHost(DEFAULT_PROXY, DEFAULT_PORT, DEFAULT_SCHEMA)).build();
    config(requestConfig);
    HttpGet httpGet = new HttpGet(EXAMPLE_URL);
    CloseableHttpResponse response = client.execute(httpGet);
    int statusCode = response.getStatusLine().getStatusCode();
    System.out.println(statusCode == HttpStatus.SC_OK);
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) HttpGet(org.apache.http.client.methods.HttpGet) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse)

Example 15 with RequestConfig

use of org.graylog.shaded.elasticsearch7.org.apache.http.client.config.RequestConfig in project libresonic by Libresonic.

the class LyricsService method executeGetRequest.

private String executeGetRequest(String url) throws IOException {
    RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(15000).setSocketTimeout(15000).build();
    HttpGet method = new HttpGet(url);
    method.setConfig(requestConfig);
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        ResponseHandler<String> responseHandler = new BasicResponseHandler();
        return client.execute(method, responseHandler);
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpGet(org.apache.http.client.methods.HttpGet) BasicResponseHandler(org.apache.http.impl.client.BasicResponseHandler)

Aggregations

RequestConfig (org.apache.http.client.config.RequestConfig)344 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)146 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)97 HttpGet (org.apache.http.client.methods.HttpGet)94 IOException (java.io.IOException)78 HttpEntity (org.apache.http.HttpEntity)67 HttpPost (org.apache.http.client.methods.HttpPost)65 HttpResponse (org.apache.http.HttpResponse)60 HttpClientBuilder (org.apache.http.impl.client.HttpClientBuilder)55 URI (java.net.URI)46 StringEntity (org.apache.http.entity.StringEntity)43 Map (java.util.Map)41 Test (org.junit.Test)41 BasicCookieStore (org.apache.http.impl.client.BasicCookieStore)33 HttpHost (org.apache.http.HttpHost)32 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)32 HttpClient (org.apache.http.client.HttpClient)31 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)27 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)24 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)24