本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}