本文整理匯總了Java中org.springframework.http.client.SimpleClientHttpRequestFactory.setConnectTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleClientHttpRequestFactory.setConnectTimeout方法的具體用法?Java SimpleClientHttpRequestFactory.setConnectTimeout怎麽用?Java SimpleClientHttpRequestFactory.setConnectTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.http.client.SimpleClientHttpRequestFactory
的用法示例。
在下文中一共展示了SimpleClientHttpRequestFactory.setConnectTimeout方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createHttpFactory
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
/**
* Extension point for plugging in different HTTP factories.
* @return Default is a {@link BufferingClientHttpRequestFactory}
*/
protected ClientHttpRequestFactory createHttpFactory(
int connectTimeout,
int requestTimeout)
{
SimpleClientHttpRequestFactory scrf = new SimpleClientHttpRequestFactory();
scrf.setConnectTimeout(connectTimeout);
scrf.setReadTimeout(requestTimeout);
//
// Wrap the default request factory in a BufferingClientHttpRequestFactory
// which allows us to read response bodies multiple times. This is needed
// because some interceptors will need to consume the body before the final
// response gets to the caller.
//
return new BufferingClientHttpRequestFactory(scrf);
}
示例2: etcdClient
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
public EtcdClient etcdClient() throws NamingException {
List<String> locations = discoverNodes("_etcd-server._tcp." + properties.getServiceName());
EtcdClient client = new EtcdClient(locations.get(0));
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;
}
示例3: initialize
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
@PostConstruct
public void initialize() {
restTemplate = new RestTemplate();
// Loose JSON serialization defaults
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.setSerializationInclusion(Include.NON_NULL);
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(objectMapper);
restTemplate.setMessageConverters(Arrays.asList(converter));
// Timeout settings
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
int tenSeconds = 10000;
requestFactory.setReadTimeout(tenSeconds);
requestFactory.setConnectTimeout(tenSeconds);
}
示例4: UrlResourceServiceRegistry
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public UrlResourceServiceRegistry(
String username,
String password,
String idpRemotePath,
String spRemotePath,
int refreshInMinutes) throws MalformedURLException {
super(false);
this.idpUrlResource = new BasicAuthenticationUrlResource(idpRemotePath, username, password);
this.spUrlResource = new BasicAuthenticationUrlResource(spRemotePath, username, password);
this.idpRemotePath = idpRemotePath;
this.spRemotePath = spRemotePath;
this.refreshInMinutes = refreshInMinutes;
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
requestFactory.setConnectTimeout(5 * 1000);
schedule(this.refreshInMinutes, TimeUnit.MINUTES);
doInitializeMetadata(true);
}
示例5: request
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
private ResponseEntity<String> request(UriComponentsBuilder uriComponentsBuilder, HttpMethod method, int connectTimeout, int readTimeout) throws RestClientException
{
LOGGER.info(uriComponentsBuilder.build(false).encode().toUriString()+" (ConenectTimeout="+connectTimeout+" ReadTimeout="+readTimeout+")");
//proxy support
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
if (LOGGER.isDebugEnabled()) LOGGER.debug("Http PROXY settings:"+HttpProxyGlobalConfigReader.getHttpProxy());
if (HttpProxyGlobalConfigReader.getHttpProxy()!=null)
factory.setProxy(HttpProxyGlobalConfigReader.getHttpProxy());
factory.setConnectTimeout(connectTimeout);
factory.setReadTimeout(readTimeout);
RestTemplate restTemplate = new RestTemplate();
restTemplate.setRequestFactory(factory);
HttpHeaders requestHeaders = new HttpHeaders();
HttpEntity<String> requestEntity = new HttpEntity<String>(requestHeaders);
return restTemplate.exchange(uriComponentsBuilder.build(false).encode().toUriString(), method, requestEntity, String.class);
}
示例6: connect
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
private T connect(final PathBuilder config) throws RestClientException {
final RestTemplate restTemplate = new RestTemplate(httpMessageConverters);
final SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(2000);
rf.setConnectTimeout(2000);
config.addParam("t", RestfulContext.getToken());
final ResponseEntity<T> re = restTemplate.getForEntity(config.buildEndpointURI(), dtoType);
return re.getBody();
}
示例7: loginDataProvider
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
/**
* Creates a login call to remote webservice.
*
* @param config
* @return token | RestClientException
*/
public static String loginDataProvider(final PathBuilder config) {
final MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("u", config.getMaster_user());
map.add("p", config.getMaster_pw());
final RestTemplate restTemplate = new RestTemplate();
final SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(3000);
rf.setConnectTimeout(30000);
try {
final URI uri = new URIBuilder().setScheme("http").setCharset(StandardCharsets.UTF_8).setHost(config
.getServer()).setPath("/ssp-data-provider/login/token").build();
final TokenWrapper result = restTemplate.postForObject(uri, map, TokenWrapper.class);
return result.getToken();
} catch (final URISyntaxException | RestClientException e) {
System.out.println("[WARNING] LoginService: " + e.getMessage());
}
return null;
}
示例8: checkIfServerAlreadyRunning
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
/**
* Checks if the data server is already running, by calling the /health endpoint.
* @return <code>true</code> if running
*/
private static boolean checkIfServerAlreadyRunning() {
logger.info("In DataServerManager.checkIfServerAlreadyRunning");
try {
// issue a GET to Spring Boot health endpoint to determine if data server is already running...
// (it returns a short JSON reply message)
RestTemplate restTemplate = new RestTemplate();
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(500); // set short connect timeout
requestFactory.setReadTimeout(2000); // set slightly longer read timeout
restTemplate.setRequestFactory(requestFactory);
String result = restTemplate.getForObject("http://localhost:9999/health", String.class);
logger.info("Server is already running, received {}", result);
return true;
} catch (RestClientException ex) {
logger.info("Server not already running");
return false;
}
}
示例9: usingJdk
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
static ClientHttpRequestFactory usingJdk(ClientOptions options) {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
if (options.getConnectionTimeout() != null) {
factory.setConnectTimeout(options.getConnectionTimeout());
}
if (options.getReadTimeout() != null) {
factory.setReadTimeout(options.getReadTimeout());
}
return factory;
}
示例10: clientHttpRequestFactory
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
private ClientHttpRequestFactory clientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setConnectTimeout(portalConfig.connectTimeout());
factory.setReadTimeout(portalConfig.readTimeout());
return factory;
}
示例11: init
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
@PostConstruct
public void init() {
restTemplate = new RestTemplate();
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
rf.setReadTimeout(portalConfig.readTimeout());
rf.setConnectTimeout(portalConfig.connectTimeout());
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(
Arrays.asList(MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM));
restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter()));
}
示例12: setTimeout
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
private void setTimeout(RestTemplate restTemplate, int timeout) {
//Explicitly setting ClientHttpRequestFactory instance to
//SimpleClientHttpRequestFactory instance to leverage
//set*Timeout methods
restTemplate.setRequestFactory(new SimpleClientHttpRequestFactory());
SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate
.getRequestFactory();
rf.setReadTimeout(timeout);
rf.setConnectTimeout(timeout);
}
示例13: setSocketTimeout
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public void setSocketTimeout(int socketTimeout) {
if (socketTimeout > 0) {
// Debug
logger.debug("Using socket timeout for REST connection: " + socketTimeout);
// Set connect and read timeouts
SimpleClientHttpRequestFactory requestFactory = (SimpleClientHttpRequestFactory) getRequestFactory();
requestFactory.setConnectTimeout(socketTimeout);
requestFactory.setReadTimeout(socketTimeout);
}
}
示例14: SimpleHttpRequester
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
/**
* Constructs an instance of the SimpleHttpRequester class with the specified connection timeout.
* <p/>
* @param connectTimeout an integer value specifying the timeout value in milliseconds for establishing the HTTP
* connection to the HTTP server.
*/
public SimpleHttpRequester(final int connectTimeout) {
final SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory();
clientHttpRequestFactory.setConnectTimeout(connectTimeout);
this.restTemplate = new RestTemplate(clientHttpRequestFactory);
}
示例15: build
import org.springframework.http.client.SimpleClientHttpRequestFactory; //導入方法依賴的package包/類
public RestTemplate build(){
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setReadTimeout(15000);//ms
factory.setConnectTimeout(10000);//ms
RestTemplate restTemplate = new RestTemplate(factory);
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(new RestTemplateAutoHeaderInterceptor());
restTemplate.setInterceptors(interceptors);
//
restTemplate.setErrorHandler(new CustomResponseErrorHandler());
return restTemplate;
}