List of usage examples for org.springframework.http.client HttpComponentsClientHttpRequestFactory HttpComponentsClientHttpRequestFactory
public HttpComponentsClientHttpRequestFactory(HttpClient httpClient)
From source file:org.slf4j.impl.PiazzaLogger.java
/** * Initializes the logger component. This will scan the environment for the URL to Piazza Logger REST endpoint. */// ww w . j av a2s .co m static void init() { if (INITIALIZED) { return; } INITIALIZED = true; // Scan the environment for the URL to Pz-Logger PZ_LOGGER_URL = System.getenv("logger.url"); System.out.println( String.format("PiazzaLogger initialized for service %s, url: %s", "serviceName", PZ_LOGGER_URL)); HttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(7500).setMaxConnPerRoute(4000).build(); restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); }
From source file:HCEngine.java
@Override public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception { ResponseEntity<String> stringResponseEntity = null; try (CloseableHttpClient hc = createCloseableHttpClient()) { for (int i = 0; i < requestOptions.getCount(); i++) { final HttpHeaders headers = new HttpHeaders(); for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) { headers.put(e.getKey(), Collections.singletonList(e.getValue())); }//from ww w . ja v a 2 s.co m final HttpEntity<Void> requestEntity = new HttpEntity<>(headers); RestTemplate template = new RestTemplate(new HttpComponentsClientHttpRequestFactory(hc)); stringResponseEntity = template.exchange(requestOptions.getUrl(), HttpMethod.GET, requestEntity, String.class); System.out.println(stringResponseEntity.getBody()); } return stringResponseEntity; } }
From source file:org.springframework.xd.dirt.security.SingleNodeApplicationWithSslTest.java
@Before public void setUpRestTemplate() throws Exception { SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory( new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build()); HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build(); HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory( httpClient);// w w w . ja v a 2 s . co m restTemplate = new RestTemplate(requestFactory); }
From source file:org.springframework.cloud.stream.binder.rabbit.admin.RabbitManagementUtils.java
public static RestTemplate buildRestTemplate(String adminUri, String user, String password) { BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(user, password)); HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); // Set up pre-emptive basic Auth because the rabbit plugin doesn't currently support challenge/response for PUT // Create AuthCache instance AuthCache authCache = new BasicAuthCache(); // Generate BASIC scheme object and add it to the local; from the apache docs... // auth cache BasicScheme basicAuth = new BasicScheme(); URI uri;//from w w w . j av a2 s. c o m try { uri = new URI(adminUri); } catch (URISyntaxException e) { throw new RabbitAdminException("Invalid URI", e); } authCache.put(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), basicAuth); // Add AuthCache to the execution context final HttpClientContext localContext = HttpClientContext.create(); localContext.setAuthCache(authCache); RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient) { @Override protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { return localContext; } }); restTemplate.setMessageConverters( Collections.<HttpMessageConverter<?>>singletonList(new MappingJackson2HttpMessageConverter())); return restTemplate; }
From source file:org.jasig.ssp.security.BasicAuthenticationRestTemplate.java
public BasicAuthenticationRestTemplate(String username, String password) { DefaultHttpClient clientd = new DefaultHttpClient(); addAuthentication(clientd, username, password); setRequestFactory(new HttpComponentsClientHttpRequestFactory(clientd)); }
From source file:dk.dma.nogoservice.service.RemoteWeatherService.java
@Autowired public RemoteWeatherService(PoolingHttpClientConnectionManager connectionManager) { CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connectionManager).build(); template = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient)); template.setErrorHandler(new RemoteErrorHandler()); }
From source file:org.energyos.espi.thirdparty.web.ClientRestTemplate.java
public ClientRestTemplate(String username, String password) { DefaultHttpClient httpClient = new DefaultHttpClient(); BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); httpClient.setCredentialsProvider(credentialsProvider); httpClient.addRequestInterceptor(new PreemptiveAuthInterceptor(), 0); ClientHttpRequestFactory rf = new HttpComponentsClientHttpRequestFactory(httpClient); this.setRequestFactory(rf); }
From source file:com.muhardin.endy.training.ws.aplikasi.absen.rest.client.AbsenRestClient.java
public AbsenRestClient() { try {// w w w .j av a 2 s. co m SSLContextBuilder builder = new SSLContextBuilder(); builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); CredentialsProvider provider = new BasicCredentialsProvider(); UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("endy", "123"); provider.setCredentials(AuthScope.ANY, credentials); HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider) .setSSLSocketFactory(sslsf).build(); restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(client)); restTemplate.setErrorHandler(new AbsenRestClientErrorHandler()); } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) { Logger.getLogger(AbsenRestClient.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.consol.citrus.samples.todolist.config.HttpClientSslConfig.java
@Bean public HttpComponentsClientHttpRequestFactory sslRequestFactory() { return new HttpComponentsClientHttpRequestFactory(httpClient()); }
From source file:org.jasig.ssp.security.BasicAuthenticationRestTemplate.java
public BasicAuthenticationRestTemplate(String username, String password, Boolean acceptEncodingGzip) { DefaultHttpClient clientd = new DefaultHttpClient(); addAuthentication(clientd, username, password); setRequestFactory(new HttpComponentsClientHttpRequestFactory(addGzip(clientd, acceptEncodingGzip))); }