Example usage for org.springframework.http.client SimpleClientHttpRequestFactory setConnectTimeout

List of usage examples for org.springframework.http.client SimpleClientHttpRequestFactory setConnectTimeout

Introduction

In this page you can find the example usage for org.springframework.http.client SimpleClientHttpRequestFactory setConnectTimeout.

Prototype

public void setConnectTimeout(int connectTimeout) 

Source Link

Document

Set the underlying URLConnection's connect timeout (in milliseconds).

Usage

From source file:edu.mayo.cts2.framework.core.client.Cts2RestClient.java

/**
 * Creates the rest template.//from ww  w .  ja  v  a  2  s  .c  o  m
 *
 * @param username the username
 * @param password the password
 * @return the rest template
 */
protected RestTemplate createRestTemplate(String username, String password) {
    RestTemplate restTemplate;
    if (username != null && password != null) {
        restTemplate = new FixedRestTemplate(this.createSecureTransport(username, password));
    } else {
        restTemplate = new FixedRestTemplate();
    }

    SimpleClientHttpRequestFactory rf = (SimpleClientHttpRequestFactory) restTemplate.getRequestFactory();
    rf.setConnectTimeout(connectTimeoutMS);
    rf.setReadTimeout(readTimeoutMS);

    List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>();

    list.add(converter);

    restTemplate.setMessageConverters(list);

    return restTemplate;
}

From source file:io.github.microcks.service.TestRunnerService.java

/** Retrieve correct test runner according given type. */
private AbstractTestRunner<HttpMethod> retrieveRunner(TestRunnerType runnerType, String serviceId) {
    // TODO: remove this ugly initialization later.
    SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
    factory.setConnectTimeout(200);
    factory.setReadTimeout(10000);/* w w w.j  av a 2s  .  com*/

    switch (runnerType) {
    case SOAP_HTTP:
        SoapHttpTestRunner soapRunner = new SoapHttpTestRunner();
        soapRunner.setClientHttpRequestFactory(factory);
        soapRunner.setResourceUrl(validationResourceUrl);
        return soapRunner;
    case OPEN_API_SCHEMA:
        OpenAPITestRunner openApiRunner = new OpenAPITestRunner(resourceRepository, responseRepository, false);
        openApiRunner.setClientHttpRequestFactory(factory);
        return openApiRunner;
    case SOAP_UI:
        // Handle local download of correct project file.
        List<ImportJob> jobs = jobRepository.findByServiceRefId(serviceId);
        if (jobs != null && !jobs.isEmpty()) {
            try {
                String projectFile = handleRemoteFileDownload(jobs.get(0).getRepositoryUrl());
                SoapUITestStepsRunner soapUIRunner = new SoapUITestStepsRunner(projectFile);
                return soapUIRunner;
            } catch (IOException ioe) {
                log.error("IOException while downloading {}", jobs.get(0).getRepositoryUrl());
            }
        }
    case POSTMAN:
        // Handle local download of correct project file.
        jobs = jobRepository.findByServiceRefId(serviceId);
        if (jobs != null && !jobs.isEmpty()) {
            try {
                String collectionFile = handleRemoteFileDownload(jobs.get(0).getRepositoryUrl());
                PostmanTestStepsRunner postmanRunner = new PostmanTestStepsRunner(collectionFile);
                postmanRunner.setClientHttpRequestFactory(factory);
                postmanRunner.setTestsCallbackUrl(testsCallbackUrl);
                postmanRunner.setPostmanRunnerUrl(postmanRunnerUrl);
                return postmanRunner;
            } catch (IOException ioe) {
                log.error("IOException while downloading {}", jobs.get(0).getRepositoryUrl());
            }
        }
    default:
        HttpTestRunner httpRunner = new HttpTestRunner();
        httpRunner.setClientHttpRequestFactory(factory);
        return httpRunner;
    }
}

From source file:net.oneandone.stool.Start.java

private void ping(Stage stage) throws IOException, SAXException, URISyntaxException, InterruptedException {
    URI uri;/*w  ww  .j  a va 2 s  . c om*/
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setConnectTimeout(500);
    console.info.println("Ping'n Applications.");
    Thread.sleep(2000);
    for (String url : stage.urlMap().values()) {
        if (url.startsWith("http://")) {
            uri = new URI(url);
            console.verbose.println("Opening connection to " + url);
            try {
                requestFactory.createRequest(uri, HttpMethod.GET).execute();
            } catch (IOException e) {
                console.verbose.println("Opening connection failed. " + e.getCause());
            }
        }
    }

}

From source file:org.zalando.boot.etcd.EtcdClient.java

/**
 * {@inheritDoc}//from   w w  w.j  av a  2  s .  co m
 * 
 * @see InitializingBean#afterPropertiesSet()
 */
@Override
public void afterPropertiesSet() throws Exception {
    if (this.requestFactory == null) {
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        requestFactory.setConnectTimeout(1000);
        requestFactory.setReadTimeout(3000);
        this.requestFactory = requestFactory;
    }

    template = new RestTemplate(this.requestFactory);
    template.setMessageConverters(Arrays.asList(requestConverter, responseConverter));

    if (locationUpdaterEnabled) {
        Runnable worker = new Runnable() {
            @Override
            public void run() {
                updateMembers();
            }
        };
        locationUpdater.scheduleAtFixedRate(worker, 5000, 5000, TimeUnit.MILLISECONDS);
    }
}

From source file:org.springframework.boot.actuate.metrics.influxdb.InfluxDBGaugeWriter.java

/**
 * Creates a new {@code InfluxDBGaugeWriter} with the given millisecond
 * {@code connectTimeout} and {@code readTimeout}.
 *
 * @param connectTimeout the connect timeout in milliseconds
 * @param readTimeout the read timeout in milliseconds
 *//* ww w. j a va  2 s  .c  o m*/
public InfluxDBGaugeWriter(int connectTimeout, int readTimeout) {
    SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
    requestFactory.setConnectTimeout(connectTimeout);
    requestFactory.setReadTimeout(readTimeout);
    this.restTemplate = new RestTemplate(requestFactory);
}