當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpComponentsClientHttpRequestFactory.setConnectionRequestTimeout方法代碼示例

本文整理匯總了Java中org.springframework.http.client.HttpComponentsClientHttpRequestFactory.setConnectionRequestTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpComponentsClientHttpRequestFactory.setConnectionRequestTimeout方法的具體用法?Java HttpComponentsClientHttpRequestFactory.setConnectionRequestTimeout怎麽用?Java HttpComponentsClientHttpRequestFactory.setConnectionRequestTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.client.HttpComponentsClientHttpRequestFactory的用法示例。


在下文中一共展示了HttpComponentsClientHttpRequestFactory.setConnectionRequestTimeout方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SmallTimeoutRestTemplateWorker

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
public SmallTimeoutRestTemplateWorker(final String url, final MetricRegistry registry, final String name,
                                      final int timeout) {

    final HttpClient httpClient = HttpClientBuilder.create()
            .setMaxConnTotal(MAX_CONN_TOTAL)
            // .setMaxConnPerRoute(MAX_CONN_PER_ROUTE)
            .build();

    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
    factory.setReadTimeout(timeout);
    factory.setConnectionRequestTimeout(timeout);
    factory.setConnectTimeout(timeout);

    this.restTemplate = new RestTemplate(factory);
    this.url = url;
    this.registry = registry;
    this.name = name;
    this.timeout = timeout;
}
 
開發者ID:vosmann,項目名稱:flechette,代碼行數:20,代碼來源:SmallTimeoutRestTemplateWorker.java

示例2: BigPoolRestTemplateWorker

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
public BigPoolRestTemplateWorker(final String url, final MetricRegistry registry, final String name,
                                 final int connectTimeout, final int readTimeout) {

    final HttpClient httpClient = HttpClientBuilder.create()
            .setMaxConnTotal(MAX_CONN_TOTAL)
            // .setMaxConnPerRoute(MAX_CONN_PER_ROUTE)
            .build();

    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
    factory.setConnectionRequestTimeout(connectTimeout); // Get from manager.
    factory.setConnectTimeout(connectTimeout); // Create connection.
    factory.setReadTimeout(readTimeout); // Socket.

    this.restTemplate = new RestTemplate(factory);
    this.url = url;
    this.registry = registry;
    this.name = name;
    this.connectTimeout = connectTimeout;
    this.readTimeout = readTimeout;
}
 
開發者ID:vosmann,項目名稱:flechette,代碼行數:21,代碼來源:BigPoolRestTemplateWorker.java

示例3: initRestTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
/**
 * springboot初始化restTemplate
 */
@Bean
public RestTemplate initRestTemplate() {
    // 長連接保持30秒
    PoolingHttpClientConnectionManager pollingConnectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS);
    // 總連接數
    pollingConnectionManager.setMaxTotal(1000);
    // 同路由的並發數
    pollingConnectionManager.setDefaultMaxPerRoute(1000);

    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.setConnectionManager(pollingConnectionManager);
    // 重試次數,默認是3次,沒有開啟
    httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true));
    // 保持長連接配置,需要在頭添加Keep-Alive
    httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());

    RequestConfig.Builder builder = RequestConfig.custom();
    builder.setConnectionRequestTimeout(200);
    builder.setConnectTimeout(5000);
    builder.setSocketTimeout(5000);

    RequestConfig requestConfig = builder.build();
    httpClientBuilder.setDefaultRequestConfig(requestConfig);

    List<Header> headers = new ArrayList<>();
    headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"));
    headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate"));
    headers.add(new BasicHeader("Accept-Language", "zh-CN"));
    headers.add(new BasicHeader("Connection", "Keep-Alive"));

    httpClientBuilder.setDefaultHeaders(headers);

    HttpClient httpClient = httpClientBuilder.build();

    // httpClient連接配置,底層是配置RequestConfig
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    // 連接超時
    clientHttpRequestFactory.setConnectTimeout(5000);
    // 數據讀取超時時間,即SocketTimeout
    clientHttpRequestFactory.setReadTimeout(5000);
    // 連接不夠用的等待時間,不宜過長,必須設置,比如連接不夠用時,時間過長將是災難性的
    clientHttpRequestFactory.setConnectionRequestTimeout(200);
    // 緩衝請求數據,默認值是true。通過POST或者PUT大量發送數據時,建議將此屬性更改為false,以免耗盡內存。
    clientHttpRequestFactory.setBufferRequestBody(false);

    // 添加內容轉換器
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(initStringHttpMessageConverter());
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new MappingJackson2XmlHttpMessageConverter());
    messageConverters.add(new MappingJackson2HttpMessageConverter());

    RestTemplate restTemplate = new RestTemplate(messageConverters);
    restTemplate.setRequestFactory(clientHttpRequestFactory);
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler());
    return restTemplate;

}
 
開發者ID:wu05281,項目名稱:admin-shiro,代碼行數:62,代碼來源:RestTemplateConfig.java

示例4: clientHttpRequestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
public ClientHttpRequestFactory clientHttpRequestFactory(HttpClient httpClient) {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
    factory.setConnectTimeout(settings.getConnectionTimeout());
    factory.setReadTimeout(settings.getReadTimeout());
    factory.setConnectionRequestTimeout(settings.getConnectionRequestTimeout());
    return factory;
}
 
開發者ID:ePages-de,項目名稱:spring-boot-readiness,代碼行數:9,代碼來源:RestTemplateConfiguration.java

示例5: setRequestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
private void setRequestFactory(final OAuth2RestTemplate restTemplate) {
    CloseableHttpClient httpClient = HttpClientBuilder.create().useSystemProperties().build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    requestFactory.setReadTimeout(this.adapterTimeoutMillis);
    requestFactory.setConnectTimeout(this.adapterTimeoutMillis);
    requestFactory.setConnectionRequestTimeout(this.adapterTimeoutMillis);
    restTemplate.setRequestFactory(requestFactory);
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:9,代碼來源:ExternalAttributeReader.java

示例6: getHttpComponentsClientHttpRequestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean(name = "httpRequestFactory")
public HttpComponentsClientHttpRequestFactory getHttpComponentsClientHttpRequestFactory(
        @Value("${ping.http.connectionRequestTimeout:60000}") final int connectionRequestTimeout,
        @Value("${ping.http.readTimeout:600000}") final int readTimeout) {
    final HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
    httpRequestFactory.setConnectionRequestTimeout(connectionRequestTimeout);
    httpRequestFactory.setReadTimeout(readTimeout);
    return httpRequestFactory;
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:10,代碼來源:AemServiceConfiguration.java

示例7: getClientHttpRequestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
/**
 * 獲取連接工廠
 *
 * @return dummy
 */
private ClientHttpRequestFactory getClientHttpRequestFactory() {
    HttpClient httpClient = getHttpClient();
    // httpClient連接配置,底層是配置RequestConfig
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    // 連接超時
    clientHttpRequestFactory.setConnectTimeout(wxProperties.getInvoker().getConnectTimeout());
    // 數據讀取超時時間,即SocketTimeout
    clientHttpRequestFactory.setReadTimeout(wxProperties.getInvoker().getReadTimeout());
    // 連接不夠用的等待時間,不宜過長,必須設置,比如連接不夠用時,時間過長將是災難性的
    clientHttpRequestFactory.setConnectionRequestTimeout(wxProperties.getInvoker().getConnectionRequestTimeout());
    return clientHttpRequestFactory;
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:18,代碼來源:WxApiHttpRequestFactory.java

示例8: pdfServerClient

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
public RestTemplate pdfServerClient() {
    HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
    httpRequestFactory.setConnectionRequestTimeout(CONNECT_TIMEOUT);
    httpRequestFactory.setReadTimeout(READ_TIMEOUT);
    httpRequestFactory.setConnectTimeout(CONNECT_TIMEOUT);

    return new RestTemplate(httpRequestFactory);
}
 
開發者ID:celestial-winter,項目名稱:vics,代碼行數:10,代碼來源:PdfServerClientConfig.java

示例9: RestTemplateWorker

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
public RestTemplateWorker(final String url, final MetricRegistry registry, final String name,
                          final int connectTimeout, final int readTimeout) {

    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setConnectionRequestTimeout(connectTimeout); // Get from manager.
    factory.setConnectTimeout(connectTimeout); // Create connection.
    factory.setReadTimeout(readTimeout); // Socket.

    this.restTemplate = new RestTemplate(factory);
    this.url = url;
    this.registry = registry;
    this.name = name;
    this.connectTimeout = connectTimeout;
    this.readTimeout = readTimeout;
}
 
開發者ID:vosmann,項目名稱:flechette,代碼行數:16,代碼來源:RestTemplateWorker.java

示例10: HttpClientTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
private HttpClientTemplate() {
    // 長連接保持30秒
    PoolingHttpClientConnectionManager pollingConnectionManager = new PoolingHttpClientConnectionManager(timeToLive, TimeUnit.SECONDS);
    // 總連接數
    pollingConnectionManager.setMaxTotal(maxTotal);
    // 同路由的並發數
    pollingConnectionManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
    HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
    httpClientBuilder.setConnectionManager(pollingConnectionManager);
    // 重試次數,默認是3次,沒有開啟
    httpClientBuilder.setRetryHandler(new DefaultHttpRequestRetryHandler(retryCount, requestSentRetryEnabled));
    // 保持長連接配置,需要在頭添加Keep-Alive
    httpClientBuilder.setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy());

    List<Header> headers = new ArrayList<>();
    // 參考:http://www.cnblogs.com/sink_cup/archive/2011/03/15/http_user_agent.html
    // headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.16 Safari/537.36"));
    // 不需要設置,可能會亂碼,請參考:http://www.crifan.com/set_accept_encoding_header_to_gzip_deflate_return_messy_code/
    // headers.add(new BasicHeader("Accept-Encoding", "gzip,deflate"));
    // headers.add(new BasicHeader("Accept-Language", "zh-CN"));
    headers.add(new BasicHeader("Connection", "Keep-Alive"));
    httpClientBuilder.setDefaultHeaders(headers);
    HttpClient httpClient = httpClientBuilder.build();

    // httpClient連接配置,底層是配置RequestConfig
    HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    // 連接超時
    clientHttpRequestFactory.setConnectTimeout(connectTimeout);
    // 數據讀取超時時間,即SocketTimeout
    clientHttpRequestFactory.setReadTimeout(readTimeout);
    // 連接不夠用的等待時間,不宜過長,必須設置,比如連接不夠用時,時間過長將是災難性的
    clientHttpRequestFactory.setConnectionRequestTimeout(connectionRequestTimeout);
    // 緩衝請求數據,默認值是true。通過POST或者PUT大量發送數據時,建議將此屬性更改為false,以免耗盡內存。
    if (!bufferRequestBody) {
        clientHttpRequestFactory.setBufferRequestBody(false);
    }
    // 添加內容轉換器
    // List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
    messageConverters.add(new FastJsonHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter(Charset.forName(charset)));
    messageConverters.add(new ByteArrayHttpMessageConverter());
    super.setMessageConverters(messageConverters);
    super.setRequestFactory(clientHttpRequestFactory);
    super.setErrorHandler(new DefaultResponseErrorHandler());
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:46,代碼來源:HttpClientTemplate.java


注:本文中的org.springframework.http.client.HttpComponentsClientHttpRequestFactory.setConnectionRequestTimeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。