當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleClientHttpRequestFactory.setConnectTimeout方法代碼示例

本文整理匯總了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);
}
 
開發者ID:HomeAdvisor,項目名稱:Robusto,代碼行數:22,代碼來源:SpringRestClient.java

示例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;
}
 
開發者ID:zalando-stups,項目名稱:spring-boot-etcd,代碼行數:18,代碼來源:EtcdClientAutoConfiguration.java

示例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);
}
 
開發者ID:jwilsoncredera,項目名稱:Profiles-Blog,代碼行數:20,代碼來源:PayloadSender.java

示例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);
}
 
開發者ID:OpenConext,項目名稱:OpenConext-pdp,代碼行數:22,代碼來源:UrlResourceServiceRegistry.java

示例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);  
}
 
開發者ID:MUNDO-platform,項目名稱:srccode,代碼行數:21,代碼來源:LocalDefaultHttpClient.java

示例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();
}
 
開發者ID:ad-tech-group,項目名稱:openssp,代碼行數:10,代碼來源:JsonDataProviderConnector.java

示例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;
}
 
開發者ID:ad-tech-group,項目名稱:openssp,代碼行數:26,代碼來源:LoginService.java

示例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;
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:25,代碼來源:DataServerManager.java

示例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;
}
 
開發者ID:spring-projects,項目名稱:spring-credhub,代碼行數:13,代碼來源:ClientHttpRequestFactoryFactory.java

示例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;
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:8,代碼來源:CtripUserService.java

示例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()));

}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:16,代碼來源:CtripMQService.java

示例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);
}
 
開發者ID:vrk-kpa,項目名稱:xroad-catalog,代碼行數:11,代碼來源:ApplicationConfiguration.java

示例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);
    }
}
 
開發者ID:nuagenetworks,項目名稱:java-bambou,代碼行數:12,代碼來源:RestClientTemplate.java

示例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);
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:14,代碼來源:SimpleHttpRequester.java

示例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;
}
 
開發者ID:vakinge,項目名稱:jeesuite-libs,代碼行數:15,代碼來源:SimpleRestTemplateBuilder.java


注:本文中的org.springframework.http.client.SimpleClientHttpRequestFactory.setConnectTimeout方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。