Java Code Examples for org.springframework.http.client.OkHttp3ClientHttpRequestFactory#setConnectTimeout()

The following examples show how to use org.springframework.http.client.OkHttp3ClientHttpRequestFactory#setConnectTimeout() . 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: HttpSyncDataService.java    From soul with Apache License 2.0 6 votes vote down vote up
private void start(final HttpConfig httpConfig) {
    // init RestTemplate
    OkHttp3ClientHttpRequestFactory factory = new OkHttp3ClientHttpRequestFactory();
    factory.setConnectTimeout((int) this.connectionTimeout.toMillis());
    factory.setReadTimeout((int) HttpConstants.CLIENT_POLLING_READ_TIMEOUT);
    this.httpClient = new RestTemplate(factory);
    // It could be initialized multiple times, so you need to control that.
    if (RUNNING.compareAndSet(false, true)) {
        // fetch all group configs.
        this.fetchGroupConfig(ConfigGroupEnum.values());
        // one thread for listener, another one for fetch configuration data.
        this.executor = new ThreadPoolExecutor(3, 3, 0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<>(),
                SoulThreadFactory.create("http-long-polling", true));
        // start long polling.
        this.executor.execute(new HttpLongPollingTask());
    } else {
        log.info("soul http long polling was started, executor=[{}]", executor);
    }
}
 
Example 2
Source File: DefaultRestExecutorFactory.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Override
public RestExecutor createRestExecutor() {
	RestExecutorConfig config = this.restExecutorConfig;
	if(config==null){
		config = new RestExecutorConfig();
	}
	ExtRestTemplate restTemplate = null;
	if(RestUtils.isOkHttp3Present()){
		OkHttp3ClientHttpRequestFactory requestFactory = new OkHttp3ClientHttpRequestFactory();
		requestFactory.setConnectTimeout(config.getConnectTimeout());
		requestFactory.setReadTimeout(config.getReadTimeout());
		requestFactory.setWriteTimeout(config.getWriteTimeout());
		restTemplate = new ExtRestTemplate(requestFactory);
	}else{
		restTemplate = new ExtRestTemplate();
	}
	return restTemplate;
}
 
Example 3
Source File: OkClientHttpRequestFactoryCreator.java    From charon-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Override
public ClientHttpRequestFactory createRequestFactory(TimeoutConfiguration configuration) {
    OkHttp3ClientHttpRequestFactory requestFactory = new OkHttp3ClientHttpRequestFactory(httpClient);
    requestFactory.setConnectTimeout(toMillis(configuration.getConnection()));
    requestFactory.setReadTimeout(toMillis(configuration.getRead()));
    requestFactory.setWriteTimeout(toMillis(configuration.getWrite()));
    return requestFactory;
}
 
Example 4
Source File: ValidationConfiguration.java    From recaptcha-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
protected RestTemplate createRestTemplate() {
    Timeout timeout = recaptcha.getValidation().getTimeout();
    OkHttp3ClientHttpRequestFactory requestFactory = new OkHttp3ClientHttpRequestFactory();
    requestFactory.setConnectTimeout(toMilliseconds(timeout.getConnect()));
    requestFactory.setReadTimeout(toMilliseconds(timeout.getRead()));
    requestFactory.setWriteTimeout(toMilliseconds(timeout.getWrite()));
    return new RestTemplate(requestFactory);
}