Java Code Examples for org.springframework.http.client.SimpleClientHttpRequestFactory#setReadTimeout()
The following examples show how to use
org.springframework.http.client.SimpleClientHttpRequestFactory#setReadTimeout() .
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: ConfigServicePropertySourceLocator.java From spring-cloud-config with Apache License 2.0 | 9 votes |
private RestTemplate getSecureRestTemplate(ConfigClientProperties client) { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); if (client.getRequestReadTimeout() < 0) { throw new IllegalStateException("Invalid Value for Read Timeout set."); } if (client.getRequestConnectTimeout() < 0) { throw new IllegalStateException("Invalid Value for Connect Timeout set."); } requestFactory.setReadTimeout(client.getRequestReadTimeout()); requestFactory.setConnectTimeout(client.getRequestConnectTimeout()); RestTemplate template = new RestTemplate(requestFactory); Map<String, String> headers = new HashMap<>(client.getHeaders()); if (headers.containsKey(AUTHORIZATION)) { headers.remove(AUTHORIZATION); // To avoid redundant addition of header } if (!headers.isEmpty()) { template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList( new GenericRequestHeaderInterceptor(headers))); } return template; }
Example 2
Source File: SentinelRuleLocator.java From Sentinel with Apache License 2.0 | 7 votes |
private RestTemplate getSecureRestTemplate(ConfigClientProperties client) { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); if (client.getRequestReadTimeout() < 0) { throw new IllegalStateException("Invalid Value for Read Timeout set."); } requestFactory.setReadTimeout(client.getRequestReadTimeout()); RestTemplate template = new RestTemplate(requestFactory); Map<String, String> headers = new HashMap<>(client.getHeaders()); if (headers.containsKey(AUTHORIZATION)) { // To avoid redundant addition of header headers.remove(AUTHORIZATION); } if (!headers.isEmpty()) { template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList( new GenericRequestHeaderInterceptor(headers))); } return template; }
Example 3
Source File: RestTemplateConfig.java From withme3.0 with MIT License | 5 votes |
@Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setReadTimeout(5000); factory.setConnectTimeout(5000); return factory; }
Example 4
Source File: GoogleConfigPropertySourceLocator.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
GoogleConfigEnvironment getRemoteEnvironment() throws IOException, HttpClientErrorException { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setReadTimeout(this.timeout); RestTemplate template = new RestTemplate(requestFactory); HttpEntity<Void> requestEntity = getAuthorizedRequest(); ResponseEntity<GoogleConfigEnvironment> response = template.exchange( RUNTIMECONFIG_API_ROOT + ALL_VARIABLES_PATH, HttpMethod.GET, requestEntity, GoogleConfigEnvironment.class, this.projectId, this.name, this.profile); if (!response.getStatusCode().is2xxSuccessful()) { throw new HttpClientErrorException(response.getStatusCode(), "Invalid response from Runtime Configurator API"); } return response.getBody(); }
Example 5
Source File: RestTemplateConfig.java From order-charge-notify with Apache License 2.0 | 5 votes |
@Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); /**读超时单位为ms*/ factory.setReadTimeout(10000); /**连接超时单位为ms*/ factory.setConnectTimeout(10000); return factory; }
Example 6
Source File: EtcdClientAutoConfiguration.java From spring-boot-etcd with MIT License | 5 votes |
@Bean public EtcdClient etcdClient() { EtcdClient client = new EtcdClient(properties.getLocation()); client.setRetryCount(properties.getRetryCount()); client.setRetryDuration(properties.getRetryDuration()); client.setLocationUpdaterEnabled(properties.isUpdateLocations()); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(properties.getConnectTimeout()); requestFactory.setReadTimeout(properties.getReadTimeout()); client.setRequestFactory(requestFactory); return client; }
Example 7
Source File: RestTemplateConfig.java From md_blockchain with Apache License 2.0 | 5 votes |
@Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory() { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setReadTimeout(5000); factory.setConnectTimeout(5000); return factory; }
Example 8
Source File: GradleUpdateHandler.java From NBANDROID-V2 with Apache License 2.0 | 5 votes |
private static void setTimeout(RestTemplate restTemplate, int connectTimeout, int readTimeout) { restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory()); SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate .getRequestFactory(); rf.setReadTimeout(readTimeout); rf.setConnectTimeout(connectTimeout); }
Example 9
Source File: SdsRestTemplate.java From sds with Apache License 2.0 | 5 votes |
@Bean public RestTemplate restTemplate() { SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory(); httpRequestFactory.setConnectTimeout(1000); httpRequestFactory.setReadTimeout(1000); return new RestTemplate(httpRequestFactory); }
Example 10
Source File: RestTemplateConfig.java From spring-boot-plus with Apache License 2.0 | 5 votes |
@Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); //单位为ms factory.setReadTimeout(5000); //单位为ms factory.setConnectTimeout(5000); return factory; }
Example 11
Source File: RestTemplateConfig.java From withme3.0 with MIT License | 5 votes |
@Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setReadTimeout(5000); factory.setConnectTimeout(5000); return factory; }
Example 12
Source File: DefaultAuthServiceImpl.java From SENS with GNU General Public License v3.0 | 5 votes |
public static RestTemplate getRestTemplate() {// 手动添加 SimpleClientHttpRequestFactory requestFactory=new SimpleClientHttpRequestFactory(); requestFactory.setReadTimeout(120000); List<HttpMessageConverter<?>> messageConverters = new LinkedList<>(); messageConverters.add(new ByteArrayHttpMessageConverter()); messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8)); messageConverters.add(new ResourceHttpMessageConverter()); messageConverters.add(new SourceHttpMessageConverter<Source>()); messageConverters.add(new AllEncompassingFormHttpMessageConverter()); messageConverters.add(new MappingJackson2HttpMessageConverter()); RestTemplate restTemplate=new RestTemplate(messageConverters); restTemplate.setRequestFactory(requestFactory); return restTemplate; }
Example 13
Source File: RestTemplateConfig.java From withme3.0 with MIT License | 5 votes |
@Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setReadTimeout(5000); factory.setConnectTimeout(5000); return factory; }
Example 14
Source File: WebClientExceptionTests.java From spring-cloud-sleuth with Apache License 2.0 | 5 votes |
@LoadBalanced @Bean public RestTemplate restTemplate() { SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory(); clientHttpRequestFactory.setReadTimeout(1); clientHttpRequestFactory.setConnectTimeout(1); return new RestTemplate(clientHttpRequestFactory); }
Example 15
Source File: RestTemplateConfig.java From seckill-rocketmq with Apache License 2.0 | 5 votes |
@Bean public ClientHttpRequestFactory simpleClientHttpRequestFactory(){ SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); /**读超时单位为ms*/ factory.setReadTimeout(10000); /**连接超时单位为ms*/ factory.setConnectTimeout(10000); return factory; }
Example 16
Source File: YandexSearchProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@PostConstruct private void init() { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout((int) HTTP_TIMEOUT_DURATION.toMillis()); requestFactory.setReadTimeout((int) HTTP_TIMEOUT_DURATION.toMillis()); var yandexProxy = workerProperties.getAudio().getYandexProxy(); if (StringUtils.isNotEmpty(yandexProxy.getHost())) { requestFactory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(yandexProxy.getHost(), yandexProxy.getPort()))); } this.restTemplate = new RestTemplate(requestFactory); }
Example 17
Source File: BeanConfig.java From WeBASE-Node-Manager with Apache License 2.0 | 5 votes |
/** * resttemplate for deploy contract. */ @Bean(name = "deployRestTemplate") public RestTemplate getDeployRestTemplate() { SimpleClientHttpRequestFactory factory = getHttpFactoryForDeploy(); factory.setReadTimeout(constantProperties.getContractDeployTimeOut());// ms factory.setConnectTimeout(constantProperties.getContractDeployTimeOut());// ms return new RestTemplate(factory); }
Example 18
Source File: BeanConfig.java From WeBASE-Node-Manager with Apache License 2.0 | 5 votes |
/** * resttemplate for generic http request. */ @Bean(name = "genericRestTemplate") public RestTemplate getRestTemplate() { SimpleClientHttpRequestFactory factory = getHttpFactoryForDeploy(); factory.setReadTimeout(constantProperties.getHttpTimeOut());// ms factory.setConnectTimeout(constantProperties.getHttpTimeOut());// ms return new RestTemplate(factory); }
Example 19
Source File: RestTemplateConfiguration.java From super-cloudops with Apache License 2.0 | 4 votes |
public ClientHttpRequestFactory simpleClientHttpRequestFactory() { SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setReadTimeout(5000); factory.setConnectTimeout(5000); return factory; }
Example 20
Source File: BmsAuthClient.java From spring-cloud-formula with Apache License 2.0 | 3 votes |
private RestTemplate getRestTemplate() { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setReadTimeout(timeout * 1000); RestTemplate template = new RestTemplate(requestFactory); template.setInterceptors(Collections.singletonList(new BmsAuthorizationInterceptor())); return template; }