Example usage for org.springframework.http.client HttpComponentsClientHttpRequestFactory HttpComponentsClientHttpRequestFactory

List of usage examples for org.springframework.http.client HttpComponentsClientHttpRequestFactory HttpComponentsClientHttpRequestFactory

Introduction

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

Prototype

public HttpComponentsClientHttpRequestFactory(HttpClient httpClient) 

Source Link

Document

Create a new instance of the HttpComponentsClientHttpRequestFactory with the given HttpClient instance.

Usage

From source file:gateway.Application.java

@Bean
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(httpMaxTotal)
            .setMaxConnPerRoute(httpMaxRoute).build();
    restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
    return restTemplate;
}

From source file:access.deploy.geoserver.PiazzaEnvironment.java

/**
 * Invokes initialization logic for Piazza workspace and PostGIS Data Store
 *//*  w  w  w. j  a va 2s.c o m*/
@PostConstruct
public void initializeEnvironment() {
    pzLogger.log("Initializing - checking GeoServer for required workspaces and data stores.",
            Severity.INFORMATIONAL);

    // Since we're on the startup thread, we want to try to complete quickly. i.e. don't wait for slow connections.
    // Configure a reasonable timeout for the rest client to abort slow requests.
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
            this.httpClient);
    requestFactory.setReadTimeout(restTemplateConnectionReadTimeout);
    restTemplate.setRequestFactory(requestFactory);

    // Check for Workspace
    try {
        String workspaceUri = String.format("%s/rest/workspaces/piazza.json",
                accessUtilities.getGeoServerBaseUrl());
        if (!doesResourceExist(workspaceUri)) {
            createWorkspace();
        } else {
            LOGGER.info("GeoServer Piazza Workspace found.");
        }
    } catch (Exception exception) {
        String error = "Server error encountered while trying to check Piazza Workspace. Will not attempt to create this Resource.";
        LOGGER.warn(error, exception);
        pzLogger.log(error, Severity.WARNING);
    }

    // Check for Data Store
    try {
        String dataStoreUri = String.format("%s/rest/workspaces/piazza/datastores/piazza.json",
                accessUtilities.getGeoServerBaseUrl());
        if (!doesResourceExist(dataStoreUri)) {
            createPostgresStore();
        } else {
            LOGGER.info("GeoServer Piazza Data Store found.");
        }
    } catch (Exception exception) {
        String error = "Server error encountered while trying to check Piazza Data Store. Will not attempt to create this Resource.";
        LOGGER.warn(error, exception);
        pzLogger.log(error, Severity.WARNING);
    }
}

From source file:io.bosh.client.SpringDirectorClientBuilder.java

private ClientHttpRequestFactory createRequestFactory(String host, String username, String password) {
    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(host, 25555),
            new UsernamePasswordCredentials(username, password));

    SSLContext sslContext = null;
    try {/*from ww  w .j a  v  a  2s .c o  m*/
        sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS()
                .build();
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
        throw new DirectorException("Unable to configure ClientHttpRequestFactory", e);
    }

    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext,
            new AllowAllHostnameVerifier());

    // disabling redirect handling is critical for the way BOSH uses 302's
    HttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling()
            .setDefaultCredentialsProvider(credentialsProvider).setSSLSocketFactory(connectionFactory).build();

    return new HttpComponentsClientHttpRequestFactory(httpClient);
}

From source file:org.squashtest.tm.plugin.testautomation.jenkins.internal.net.HttpClientProvider.java

public HttpClientProvider() {
    PoolingHttpClientConnectionManager manager = new PoolingHttpClientConnectionManager();
    manager.setMaxTotal(25);// w  ww  . j a v a  2  s.co m

    client = HttpClients.custom().setConnectionManager(manager)
            .addInterceptorFirst(new PreemptiveAuthInterceptor())
            .setDefaultCredentialsProvider(credentialsProvider).build();

    requestFactory = new HttpComponentsClientHttpRequestFactory(client);
}

From source file:es.ujaen.dae.restClient.controllers.SessionBackingBean.java

public String login() {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(user.getName(), user.getPassword()));
    ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient);
    template = new RestTemplate(rf);
    try {/*  w w  w.  jav  a2  s  . c o  m*/
        template.getForObject(URL + "users/loginTest", String.class);
        loggedIn = true;
        return "userMenu?faces-redirect=true";
    } catch (HttpClientErrorException e) {
        loggedIn = false;
        user.setPassword("");
        return "loginError?faces-redirect=true";
    }

}

From source file:com.hybris.datahub.outbound.utils.RestTemplateUtil.java

private RestTemplate initializationTemplate() {
    final ConnectionConfig connConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build();
    final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(100000).build();
    final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder
            .<ConnectionSocketFactory>create();
    final ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory();
    registryBuilder.register("http", plainSF);

    registryBuilder.register("https", setUpSSL());

    final Registry<ConnectionSocketFactory> registry = registryBuilder.build();
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);
    connManager.setDefaultConnectionConfig(connConfig);
    connManager.setDefaultSocketConfig(socketConfig);
    connManager.setMaxTotal(1000);/*from w  w  w.  j a  v  a  2 s.c o m*/
    connManager.setDefaultMaxPerRoute(1000);
    final HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build();

    final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(
            httpClient);
    clientHttpRequestFactory.setConnectTimeout(50000);
    clientHttpRequestFactory.setReadTimeout(30000);
    // clientHttpRequestFactory.setConnectionRequestTimeout(200);

    restTemplate = new RestTemplate();
    restTemplate.setRequestFactory(clientHttpRequestFactory);
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler());

    return restTemplate;
}

From source file:io.pivotal.strepsirrhini.chaoslemur.infrastructure.StandardDirectorUtils.java

private static String getBoshDirectorUaaToken(String host, String directorName, String password)
        throws GeneralSecurityException {

    SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS()
            .build();/*from  w  ww .jav a 2s.c  o  m*/

    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext,
            new AllowAllHostnameVerifier());

    HttpClient httpClient = HttpClientBuilder.create().disableRedirectHandling()
            .setSSLSocketFactory(connectionFactory).build();
    RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));

    MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
    String base64Passowrd = encodePassword(directorName, password);
    headers.add("Authorization", "Basic " + base64Passowrd);
    headers.add("Content-Type", "application/x-www-form-urlencoded");

    String postArgs = "grant_type=client_credentials";

    HttpEntity<String> requestEntity = new HttpEntity<String>(postArgs, headers);
    String uri = "https://" + host + ":8443/oauth/token";
    UaaToken response = restTemplate.postForObject(uri, requestEntity, UaaToken.class);

    log.info("Uaa token:" + response);
    return response.getAccess_token();
}

From source file:de.hybris.platform.marketplaceintegrationbackoffice.utils.MarketplaceintegrationbackofficeRestTemplateUtil.java

private RestTemplate initializationTemplate() {
    final ConnectionConfig connConfig = ConnectionConfig.custom().setCharset(Charset.forName("UTF-8")).build();
    final SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(100000).build();
    final RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder
            .<ConnectionSocketFactory>create();
    final ConnectionSocketFactory plainSF = new PlainConnectionSocketFactory();
    registryBuilder.register("http", plainSF);

    registryBuilder.register("https", setUpSSL());

    final Registry<ConnectionSocketFactory> registry = registryBuilder.build();
    final PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry);
    connManager.setDefaultConnectionConfig(connConfig);
    connManager.setDefaultSocketConfig(socketConfig);
    connManager.setMaxTotal(1000);/*from   w ww.ja v a2  s  . co m*/
    connManager.setDefaultMaxPerRoute(1000);
    final HttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connManager).build();

    final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(
            httpClient);
    clientHttpRequestFactory.setConnectTimeout(5000);
    clientHttpRequestFactory.setReadTimeout(5000);
    clientHttpRequestFactory.setConnectionRequestTimeout(200);

    restTemplate = new RestTemplate();
    restTemplate.setRequestFactory(clientHttpRequestFactory);
    restTemplate.setErrorHandler(new DefaultResponseErrorHandler());

    return restTemplate;
}