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:es.ujaen.dae.restClient.controllers.SessionBackingBean.java

public SessionBackingBean() {
    user = new UsersDTO();
    wall = new ArrayList();
    message = new CommentDTO();
    task = new TaskDTO();
    loggedIn = false;//from  w  ww  .  j a v  a  2s .  c o  m
    usersFound = new ArrayList();
    editTask = false;
    lTask = new ArrayList();
    hasNotifications = false;
    DefaultHttpClient httpClient = new DefaultHttpClient();
    ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient);
    template = new RestTemplate(rf);
}

From source file:org.obiba.mica.core.service.AgateRestService.java

protected RestTemplate newRestTemplate() {
    log.info("Connecting to Agate: {}", agateUrl);
    if (agateUrl.toLowerCase().startsWith("https://")) {
        if (httpRequestFactory == null) {
            httpRequestFactory = new HttpComponentsClientHttpRequestFactory(createHttpClient());
        }/*from   www  .  jav a 2  s  .  c  om*/
        return new RestTemplate(httpRequestFactory);
    } else {
        return new RestTemplate();
    }
}

From source file:com.epam.reportportal.gateway.CompositeInfoEndpoint.java

@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired/* w  w w . j  a v a2 s.  c  om*/
public CompositeInfoEndpoint(RestTemplate loadBalancedRestTemplate, DiscoveryClient discoveryClient,
        EurekaClient eurekaClient) {
    this.restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(
            HttpClientBuilder.create().setSSLHostnameVerifier((s, sslSession) -> true).build()));

    this.loadBalancedRestTemplate = loadBalancedRestTemplate;
    this.discoveryClient = discoveryClient;
    this.eurekaClient = eurekaClient;
}

From source file:org.springframework.http.server.reactive.ServerHttpsRequestIntegrationTests.java

@Before
public void setup() throws Exception {
    this.server.setHandler(new CheckRequestHandler());
    this.server.afterPropertiesSet();
    this.server.start();

    // Set dynamically chosen port
    this.port = this.server.getPort();

    SSLContextBuilder builder = new SSLContextBuilder();
    builder.loadTrustMaterial(new TrustSelfSignedStrategy());
    SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(builder.build(),
            NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
            httpclient);/*from  w w w  .j  a v  a 2 s .c  o m*/
    this.restTemplate = new RestTemplate(requestFactory);
}

From source file:org.trustedanalytics.servicebroker.hdfs.config.hgm.HgmHttpsConfiguration.java

@Bean
@Qualifier("hgmRestTemplate")
public RestTemplate getHgmHttpsRestTemplate()
        throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
    SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).useTLS()
            .build();/*from www  .j  ava  2 s  .c o m*/
    SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext,
            new AllowAllHostnameVerifier());
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword()));

    HttpClient httpClient = HttpClientBuilder.create().setSSLSocketFactory(connectionFactory)
            .setDefaultCredentialsProvider(credentialsProvider).build();

    ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
    return new RestTemplate(requestFactory);
}

From source file:org.springframework.xd.shell.security.SecuredShellAccessWithSslTest.java

@Test
public void testSpringXDTemplate() throws Exception {
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("admin", "whosThere"));
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(
            HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider)
                    .setSSLSocketFactory(new SSLConnectionSocketFactory(new SSLContextBuilder()
                            .loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()))
                    .build());/*from  w ww.  ja  v  a 2 s. c  o  m*/
    SpringXDTemplate template = new SpringXDTemplate(requestFactory, new URI("https://localhost:" + adminPort));
    PagedResources<ModuleDefinitionResource> moduleDefinitions = template.moduleOperations()
            .list(RESTModuleType.sink);
    assertThat(moduleDefinitions.getLinks().size(), greaterThan(0));
}

From source file:com.nouveauxterritoires.eterritoires.identityserver.openid.connect.client.TaxeUserInfoFetcher.java

public UserInfo loadUserInfo(final OIDCAuthenticationToken token) {

    ServerConfiguration serverConfiguration = token.getServerConfiguration();

    if (serverConfiguration == null) {
        logger.warn("No server configuration found.");
        return null;
    }//w  ww. j  a v  a  2  s  .  c  o m

    if (Strings.isNullOrEmpty(serverConfiguration.getUserInfoUri())) {
        logger.warn("No userinfo endpoint, not fetching.");
        return null;
    }

    try {

        // if we got this far, try to actually get the userinfo
        HttpClient httpClient = new SystemDefaultHttpClient();

        HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);

        String userInfoString = null;

        if (serverConfiguration.getUserInfoTokenMethod() == null
                || serverConfiguration.getUserInfoTokenMethod().equals(UserInfoTokenMethod.HEADER)) {
            RestTemplate restTemplate = new RestTemplate(factory) {

                @Override
                protected ClientHttpRequest createRequest(URI url, HttpMethod method) throws IOException {
                    ClientHttpRequest httpRequest = super.createRequest(url, method);
                    httpRequest.getHeaders().add("Authorization",
                            String.format("Bearer %s", token.getAccessTokenValue()));
                    return httpRequest;
                }
            };

            userInfoString = restTemplate.getForObject(serverConfiguration.getUserInfoUri(), String.class);

        } else if (serverConfiguration.getUserInfoTokenMethod().equals(UserInfoTokenMethod.FORM)) {
            MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
            form.add("access_token", token.getAccessTokenValue());

            RestTemplate restTemplate = new RestTemplate(factory);
            userInfoString = restTemplate.postForObject(serverConfiguration.getUserInfoUri(), form,
                    String.class);
        } else if (serverConfiguration.getUserInfoTokenMethod().equals(UserInfoTokenMethod.QUERY)) {
            URIBuilder builder = new URIBuilder(serverConfiguration.getUserInfoUri());
            builder.setParameter("access_token", token.getAccessTokenValue());

            RestTemplate restTemplate = new RestTemplate(factory);
            userInfoString = restTemplate.getForObject(builder.toString(), String.class);
        }

        if (!Strings.isNullOrEmpty(userInfoString)) {

            JsonObject userInfoJson = new JsonParser().parse(userInfoString).getAsJsonObject();

            UserInfo userInfo = TaxeUserInfo.fromJson(userInfoJson);

            return userInfo;
        } else {
            // didn't get anything, return null
            return null;
        }
    } catch (Exception e) {
        logger.warn("Error fetching taxeuserinfo", e);
        return null;
    }

}

From source file:dk.clanie.bitcoin.client.BitcoindClientDefaultConfig.java

private ClientHttpRequestFactory requestFactory() {
    return new HttpComponentsClientHttpRequestFactory(httpClient());
}

From source file:org.venice.piazza.servicecontroller.Application.java

@Bean
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(httpMaxTotal)
            .setMaxConnPerRoute(httpMaxRoute).build();
    HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
    factory.setReadTimeout(httpRequestTimeout * 1000);
    factory.setConnectTimeout(httpRequestTimeout * 1000);
    restTemplate.setRequestFactory(factory);

    return restTemplate;
}

From source file:sample.tomcat.X509ApplicationTests.java

@Test
public void testAuthenticatedHello() throws Exception {
    RestTemplate template = new TestRestTemplate();
    final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(
            httpClient());//w w w  .  j  a  v a2  s  .  co  m
    template.setRequestFactory(factory);

    ResponseEntity<String> httpsEntity = template.getForEntity("https://localhost:" + this.port + "/hello",
            String.class);
    assertEquals(HttpStatus.OK, httpsEntity.getStatusCode());
    assertEquals("hello", httpsEntity.getBody());
}