Java Code Examples for org.springframework.http.client.HttpComponentsClientHttpRequestFactory#setConnectionRequestTimeout()
The following examples show how to use
org.springframework.http.client.HttpComponentsClientHttpRequestFactory#setConnectionRequestTimeout() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WxApiHttpRequestFactory.java From FastBootWeixin with Apache License 2.0 | 6 votes |
/** * 获取连接工厂 * * @return the result */ 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; }
Example 2
Source File: AemServiceConfiguration.java From jwala with Apache License 2.0 | 5 votes |
@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; }
Example 3
Source File: CommonUtils.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
public static HttpComponentsClientHttpRequestFactory createRequestFactory() { HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(); httpRequestFactory.setConnectTimeout(HTTP_TIMEOUT); httpRequestFactory.setReadTimeout(HTTP_TIMEOUT); httpRequestFactory.setConnectionRequestTimeout(HTTP_TIMEOUT); return httpRequestFactory; }
Example 4
Source File: PdfServerClientConfig.java From vics with MIT License | 5 votes |
@Bean public RestTemplate pdfServerClient() { HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(); httpRequestFactory.setConnectionRequestTimeout(CONNECT_TIMEOUT); httpRequestFactory.setReadTimeout(READ_TIMEOUT); httpRequestFactory.setConnectTimeout(CONNECT_TIMEOUT); return new RestTemplate(httpRequestFactory); }
Example 5
Source File: DockerCompose.java From football-events with MIT License | 4 votes |
private RestTemplate restTemplate(long healthCheckTimeout) { HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(); clientHttpRequestFactory.setConnectTimeout(2000); clientHttpRequestFactory.setConnectionRequestTimeout(2000); return new RestTemplate(clientHttpRequestFactory); }
Example 6
Source File: RestTemplateConfig.java From LicenseDemo with Apache License 2.0 | 4 votes |
/** * ClientHttpRequestFactory接口的另一种实现方式(推荐使用),即: * HttpComponentsClientHttpRequestFactory:底层使用Httpclient连接池的方式创建Http连接请求 * @return HttpComponentsClientHttpRequestFactory */ @Bean public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory(){ //Httpclient连接池,长连接保持30秒 PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS); //设置总连接数 connectionManager.setMaxTotal(1000); //设置同路由的并发数 connectionManager.setDefaultMaxPerRoute(1000); //设置header List<Header> headers = new ArrayList<Header>(); headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04")); headers.add(new BasicHeader("Accept-Encoding", "gzip, deflate")); headers.add(new BasicHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")); headers.add(new BasicHeader("Connection", "keep-alive")); //创建HttpClient HttpClient httpClient = HttpClientBuilder.create() .setConnectionManager(connectionManager) .setDefaultHeaders(headers) .setRetryHandler(new DefaultHttpRequestRetryHandler(3, true)) //设置重试次数 .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()) //设置保持长连接 .build(); //创建HttpComponentsClientHttpRequestFactory实例 HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); //设置客户端和服务端建立连接的超时时间 requestFactory.setConnectTimeout(5000); //设置客户端从服务端读取数据的超时时间 requestFactory.setReadTimeout(5000); //设置从连接池获取连接的超时时间,不宜过长 requestFactory.setConnectionRequestTimeout(200); //缓冲请求数据,默认为true。通过POST或者PUT大量发送数据时,建议将此更改为false,以免耗尽内存 requestFactory.setBufferRequestBody(false); return requestFactory; }
Example 7
Source File: RestTemplateConfig.java From LicenseDemo with Apache License 2.0 | 4 votes |
/** * ClientHttpRequestFactory接口的另一种实现方式(推荐使用),即: * HttpComponentsClientHttpRequestFactory:底层使用Httpclient连接池的方式创建Http连接请求 * @return HttpComponentsClientHttpRequestFactory */ @Bean public HttpComponentsClientHttpRequestFactory httpComponentsClientHttpRequestFactory(){ //Httpclient连接池,长连接保持30秒 PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(30, TimeUnit.SECONDS); //设置总连接数 connectionManager.setMaxTotal(1000); //设置同路由的并发数 connectionManager.setDefaultMaxPerRoute(1000); //设置header List<Header> headers = new ArrayList<Header>(); headers.add(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; rv:36.0) Gecko/20100101 Firefox/36.04")); headers.add(new BasicHeader("Accept-Encoding", "gzip, deflate")); headers.add(new BasicHeader("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3")); headers.add(new BasicHeader("Connection", "keep-alive")); //创建HttpClient HttpClient httpClient = HttpClientBuilder.create() .setConnectionManager(connectionManager) .setDefaultHeaders(headers) .setRetryHandler(new DefaultHttpRequestRetryHandler(3, true)) //设置重试次数 .setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy()) //设置保持长连接 .build(); //创建HttpComponentsClientHttpRequestFactory实例 HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); //设置客户端和服务端建立连接的超时时间 requestFactory.setConnectTimeout(5000); //设置客户端从服务端读取数据的超时时间 requestFactory.setReadTimeout(5000); //设置从连接池获取连接的超时时间,不宜过长 requestFactory.setConnectionRequestTimeout(200); //缓冲请求数据,默认为true。通过POST或者PUT大量发送数据时,建议将此更改为false,以免耗尽内存 requestFactory.setBufferRequestBody(false); return requestFactory; }