当前位置: 首页>>代码示例>>Java>>正文


Java HttpComponentsClientHttpRequestFactory.setReadTimeout方法代码示例

本文整理汇总了Java中org.springframework.http.client.HttpComponentsClientHttpRequestFactory.setReadTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java HttpComponentsClientHttpRequestFactory.setReadTimeout方法的具体用法?Java HttpComponentsClientHttpRequestFactory.setReadTimeout怎么用?Java HttpComponentsClientHttpRequestFactory.setReadTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.http.client.HttpComponentsClientHttpRequestFactory的用法示例。


在下文中一共展示了HttpComponentsClientHttpRequestFactory.setReadTimeout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: requestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
@Bean
public ClientHttpRequestFactory requestFactory() {

	// Disable auto redirect on 3xx HTTP responses
	CloseableHttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling().build();

	HttpComponentsClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient);

	// read timeout
	if(!StringUtils.isEmpty(readTimeout)) {
		rf.setReadTimeout(Integer.valueOf(readTimeout) * 1000);
	}

	// connect timeout
	if(!StringUtils.isEmpty(connectTimeout)) {
		rf.setConnectTimeout(Integer.valueOf(connectTimeout) * 1000);
	}

	return rf;
}
 
开发者ID:vianneyfaivre,项目名称:Persephone,代码行数:21,代码来源:DefaultRestTemplateConfig.java

示例4: afterPropertiesSet

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
public void afterPropertiesSet() throws UnsupportedEncodingException {
  Collection<Header> defaultHeaders = new ArrayList<Header>();
  Header header = new BasicHeader("Authorization",
      "Basic " + BaseEncoding.base64().encode("apollo:".getBytes("UTF-8")));
  defaultHeaders.add(header);

  BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY,
      new UsernamePasswordCredentials("apollo", ""));
  CloseableHttpClient httpClient =
      HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider)
          .setDefaultHeaders(defaultHeaders).build();


  restTemplate = new RestTemplate(httpMessageConverters.getConverters());
  HttpComponentsClientHttpRequestFactory requestFactory =
      new HttpComponentsClientHttpRequestFactory(httpClient);
  requestFactory.setConnectTimeout(portalConfig.connectTimeout());
  requestFactory.setReadTimeout(portalConfig.readTimeout());

  restTemplate.setRequestFactory(requestFactory);
}
 
开发者ID:dewey-its,项目名称:apollo-custom,代码行数:23,代码来源:RestTemplateFactory.java

示例5: increaseReadTimeoutForStreamedTailedLogs

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
public void increaseReadTimeoutForStreamedTailedLogs(int timeout) {
    // May temporary increase read timeout on other unrelated concurrent
    // threads, but per-request read timeout don't seem easily
    // accessible
    if (delegate instanceof HttpComponentsClientHttpRequestFactory) {
        HttpComponentsClientHttpRequestFactory httpRequestFactory = (HttpComponentsClientHttpRequestFactory) delegate;

        if (timeout > 0) {
            httpRequestFactory.setReadTimeout(timeout);
        } else {
            httpRequestFactory.setReadTimeout(defaultSocketTimeout);
        }
    }
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:15,代码来源:CloudControllerClientImpl.java

示例6: getFactoryDisabledSslChecks

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
/**
 * WARNING!!! disabling is not a good idea.
 * 
 * Support hardcode for ps team
 * 
 * Their server is pretty busted. -
 * http://stackoverflow.com/questions/7615645
 * /ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0
 * -- -Djsse.enableSNIExtension=false very ugly workaround
 * 
 * @param restTemplate
 * @throws Exception
 */
public static HttpComponentsClientHttpRequestFactory getFactoryDisabledSslChecks(
		int connectTimeoutMs, int readTimeoutMs) throws Exception {

	SSLContextBuilder builder = new SSLContextBuilder();
	builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
	// builder.loadTrustMaterial(null, new TrustStrategy() {
	//
	// @Override
	// public boolean isTrusted(X509Certificate[] chain, String authType)
	// throws CertificateException {
	//
	// return true;
	// }
	// });

	SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
			builder.build(), new NoopHostnameVerifier());

	CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(
			sslsf).build();

	HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
	factory.setHttpClient(httpClient);
	// factory.getHttpClient().getConnectionManager().getSchemeRegistry().register(scheme);

	factory.setConnectTimeout(connectTimeoutMs);
	factory.setReadTimeout(readTimeoutMs);

	// restTemplate.setRequestFactory(factory);
	return factory;
}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:45,代码来源:NagiosIntegration.java

示例7: getRestTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
private RestTemplate getRestTemplate ( long maxConnectionInMs, JsonNode user, JsonNode pass, String desc ) {

		logger.debug( "maxConnectionInMs: {} , user: {} , Pass: {} ", maxConnectionInMs, user, pass );

		HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();

		// "user" : "$csapUser1", "pass" : "$csapPass1"
		if ( user != null && pass != null ) {
			CredentialsProvider credsProvider = new BasicCredentialsProvider();
			credsProvider.setCredentials(
				new AuthScope( null, -1 ),
				new UsernamePasswordCredentials(
					user.asText(),
					csapApplication.decode( pass.asText(), desc ) ) );

			HttpClient httpClient = HttpClients
				.custom()
				.setDefaultCredentialsProvider( credsProvider )
				.build();
			factory.setHttpClient( httpClient );
			// factory = new HttpComponentsClientHttpRequestFactory(httpClient);
		}

		factory.setConnectTimeout( (int) maxConnectionInMs );
		factory.setReadTimeout( (int) maxConnectionInMs );

		RestTemplate restTemplate = new RestTemplate( factory );

		return restTemplate;
	}
 
开发者ID:csap-platform,项目名称:csap-core,代码行数:31,代码来源:HttpCollector.java

示例8: createRestTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
protected RestTemplate createRestTemplate() {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(PACT_DOWNLOAD_TIMEOUT_MILLIS);
    factory.setConnectTimeout(PACT_DOWNLOAD_TIMEOUT_MILLIS);

    return new RestTemplate(factory);
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:8,代码来源:DefaultPactResolver.java

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: init

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
@PostConstruct
private void init() {
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
    factory.setReadTimeout(API_TIMEOUT_IN_MILLIS);
    factory.setConnectTimeout(API_TIMEOUT_IN_MILLIS);

    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    mapper.setPropertyNamingStrategy(new PropertyNamingStrategy.SnakeCaseStrategy());

    restTemplate = new RestTemplate(Collections.singletonList(new MappingJackson2HttpMessageConverter(mapper)));
    restTemplate.setRequestFactory(factory);
}
 
开发者ID:RWTH-i5-IDSG,项目名称:steve-plugsurfing,代码行数:14,代码来源:GithubReleaseCheckService.java

示例15: afterPropertiesSet

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //导入方法依赖的package包/类
public void afterPropertiesSet() throws UnsupportedEncodingException {
  CloseableHttpClient httpClient = HttpClientBuilder.create().build();

  restTemplate = new RestTemplate(httpMessageConverters.getConverters());
  HttpComponentsClientHttpRequestFactory requestFactory =
      new HttpComponentsClientHttpRequestFactory(httpClient);
  requestFactory.setConnectTimeout(portalConfig.connectTimeout());
  requestFactory.setReadTimeout(portalConfig.readTimeout());

  restTemplate.setRequestFactory(requestFactory);
}
 
开发者ID:ctripcorp,项目名称:apollo,代码行数:12,代码来源:RestTemplateFactory.java


注:本文中的org.springframework.http.client.HttpComponentsClientHttpRequestFactory.setReadTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。