當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpComponentsClientHttpRequestFactory.setHttpClient方法代碼示例

本文整理匯總了Java中org.springframework.http.client.HttpComponentsClientHttpRequestFactory.setHttpClient方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpComponentsClientHttpRequestFactory.setHttpClient方法的具體用法?Java HttpComponentsClientHttpRequestFactory.setHttpClient怎麽用?Java HttpComponentsClientHttpRequestFactory.setHttpClient使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.http.client.HttpComponentsClientHttpRequestFactory的用法示例。


在下文中一共展示了HttpComponentsClientHttpRequestFactory.setHttpClient方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: restTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {

    SSLContext sslContext = SSLContexts.custom()
            .loadTrustMaterial(null, new TrustSelfSignedStrategy())
            .build();

    SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
    CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(sslConnectionSocketFactory)
            .build();

    HttpComponentsClientHttpRequestFactory requestFactory =
            new HttpComponentsClientHttpRequestFactory();

    requestFactory.setHttpClient(httpClient);

    return new RestTemplate(requestFactory);
}
 
開發者ID:borysfan,項目名稱:websocket-poc,代碼行數:20,代碼來源:App.java

示例2: getChecksum

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
private String getChecksum(String defaultValue, String url,
		String version) {
	String result = defaultValue;
	if (result == null && StringUtils.hasText(url)) {
		CloseableHttpClient httpClient = HttpClients.custom()
				.setSSLHostnameVerifier(new NoopHostnameVerifier())
				.build();
		HttpComponentsClientHttpRequestFactory requestFactory
				= new HttpComponentsClientHttpRequestFactory();
		requestFactory.setHttpClient(httpClient);
		url = constructUrl(url, version);
		try {
			ResponseEntity<String> response
					= new RestTemplate(requestFactory).exchange(
					url, HttpMethod.GET, null, String.class);
			if (response.getStatusCode().equals(HttpStatus.OK)) {
				result = response.getBody();
			}
		}
		catch (HttpClientErrorException httpException) {
			// no action necessary set result to undefined
			logger.debug("Didn't retrieve checksum because", httpException);
		}
	}
	return result;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:27,代碼來源:AboutController.java

示例3: createTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
public RestTemplate createTemplate(final String host, final Integer port, final String username, final String password)
{
	Preconditions.checkArgument(StringUtils.isNotBlank(host));
	Preconditions.checkArgument(port != null);
	Preconditions.checkArgument(StringUtils.isNotBlank(username));
	Preconditions.checkArgument(StringUtils.isNotBlank(password));

	final AuthScope authscope = new AuthScope(host, port.intValue());
	final Credentials credentials = new UsernamePasswordCredentials(username, password);
	final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
	credentialsProvider.setCredentials(authscope, credentials);

	final HttpClientBuilder clientBuilder = HttpClientBuilder.create();
	clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
	final CloseableHttpClient httpClient = clientBuilder.build();

	final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
	requestFactory.setHttpClient(httpClient);

	return new RestTemplate(requestFactory);
}
 
開發者ID:fredhopper,項目名稱:hybris-connector,代碼行數:22,代碼來源:RestTemplateProvider.java

示例4: createSecurityRestTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
/**
 * Creates the security rest template.
 *
 * @throws KeyManagementException the key management exception
 * @throws NoSuchAlgorithmException the no such algorithm exception
 * @throws KeyStoreException the key store exception
 */
private void createSecurityRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException{
	TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;
	SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
	        .loadTrustMaterial(null, acceptingTrustStrategy)
	        .build();
	SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);
	
	HttpComponentsClientHttpRequestFactory requestFactory =
	        new HttpComponentsClientHttpRequestFactory();
	
	 HttpClient httpClient = HttpClientBuilder.create()
               .disableCookieManagement()
               .useSystemProperties()
               .setSSLSocketFactory(csf)
               .build();
	requestFactory.setHttpClient(httpClient);
	this.restTemplate = new RestTemplate(requestFactory);
}
 
開發者ID:ac-silva,項目名稱:desafio-pagarme,代碼行數:26,代碼來源:Client.java

示例5: disableSSL

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
public static void disableSSL(RestTemplate restTemplate) {
    try {
        SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
            .loadTrustMaterial(null, (X509Certificate[] chain, String authType) -> true)
            .build();
        CloseableHttpClient httpClient = HttpClients.custom()
            .setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE))
            .build();
        HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
        requestFactory.setHttpClient(httpClient);
        restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(requestFactory));
    } catch (Exception e) {
        log.error("Exception occurred while creating http factory, error={}", e.getMessage(), e);
    }
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:16,代碼來源:TemplateUtil.java

示例6: getFactoryDisabledSslChecks

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
/**
 * WARNING!!! disabling is not a good idea.
 * 
 * Support hardcode for ps team
 * 
 * Their server is pretty busted. -
 * http://stackoverflow.com/questions/7615645
 * /ssl-handshake-alert-unrecognized-name-error-since-upgrade-to-java-1-7-0
 * -- -Djsse.enableSNIExtension=false very ugly workaround
 * 
 * @param restTemplate
 * @throws Exception
 */
public static HttpComponentsClientHttpRequestFactory getFactoryDisabledSslChecks(
		int connectTimeoutMs, int readTimeoutMs) throws Exception {

	SSLContextBuilder builder = new SSLContextBuilder();
	builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
	// builder.loadTrustMaterial(null, new TrustStrategy() {
	//
	// @Override
	// public boolean isTrusted(X509Certificate[] chain, String authType)
	// throws CertificateException {
	//
	// return true;
	// }
	// });

	SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
			builder.build(), new NoopHostnameVerifier());

	CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(
			sslsf).build();

	HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
	factory.setHttpClient(httpClient);
	// factory.getHttpClient().getConnectionManager().getSchemeRegistry().register(scheme);

	factory.setConnectTimeout(connectTimeoutMs);
	factory.setReadTimeout(readTimeoutMs);

	// restTemplate.setRequestFactory(factory);
	return factory;
}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:45,代碼來源:NagiosIntegration.java

示例7: getRestTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
private RestTemplate getRestTemplate ( long maxConnectionInMs, JsonNode user, JsonNode pass, String desc ) {

		logger.debug( "maxConnectionInMs: {} , user: {} , Pass: {} ", maxConnectionInMs, user, pass );

		HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();

		// "user" : "$csapUser1", "pass" : "$csapPass1"
		if ( user != null && pass != null ) {
			CredentialsProvider credsProvider = new BasicCredentialsProvider();
			credsProvider.setCredentials(
				new AuthScope( null, -1 ),
				new UsernamePasswordCredentials(
					user.asText(),
					csapApplication.decode( pass.asText(), desc ) ) );

			HttpClient httpClient = HttpClients
				.custom()
				.setDefaultCredentialsProvider( credsProvider )
				.build();
			factory.setHttpClient( httpClient );
			// factory = new HttpComponentsClientHttpRequestFactory(httpClient);
		}

		factory.setConnectTimeout( (int) maxConnectionInMs );
		factory.setReadTimeout( (int) maxConnectionInMs );

		RestTemplate restTemplate = new RestTemplate( factory );

		return restTemplate;
	}
 
開發者ID:csap-platform,項目名稱:csap-core,代碼行數:31,代碼來源:HttpCollector.java

示例8: httpRequestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
@Autowired
public ClientHttpRequestFactory httpRequestFactory(HttpClient httpClient) {
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(httpClient);
    return requestFactory;
}
 
開發者ID:quanticc,項目名稱:ugc-bot-redux,代碼行數:8,代碼來源:RestConfiguration.java

示例9: instanceLogsRequestFactory

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
@ConditionalOnMissingBean(value = ClientHttpRequestFactory.class, name = "instanceLogsRequestFactory")
public ClientHttpRequestFactory instanceLogsRequestFactory(final Logbook logbook) {
    CloseableHttpClient client = HttpClientBuilder.create()
            .addInterceptorFirst(new LogbookHttpRequestInterceptor(logbook))
            .addInterceptorFirst(new LogbookHttpResponseInterceptor())
            .build();
    final HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory();
    httpRequestFactory.setHttpClient(client);
    return httpRequestFactory;
}
 
開發者ID:zalando-stups,項目名稱:log-sink,代碼行數:12,代碼來源:InstanceLogsConfiguration.java

示例10: apostar

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@RequestMapping(value="/apostar", method=RequestMethod.POST)
public String apostar(Model model, @RequestParam Partido partido, @RequestParam double cuota,
		@RequestParam int resultado, @RequestParam double cantidad, @RequestParam String redirect) throws NoSuchAlgorithmException, KeyStoreException, KeyStoreException, KeyStoreException, KeyStoreException, KeyManagementException, KeyStoreException, KeyStoreException {
	Usuario usuario = sessionService.getUsuarioActual();
	
	if (usuario == null) {
		flashService.setError("Tienes que iniciar sesion");
	} else {
		Apuesta apuesta = new Apuesta(partido, usuario, cuota, cantidad, new Date(), resultado);
		
		String url = internalServiceURL + "/apuesta";

		String plainCreds = internalServiceUser + ":" + internalServicePasswordt;
		byte[] plainCredsBytes = plainCreds.getBytes();
		byte[] base64CredsBytes = Base64.getEncoder().encode(plainCredsBytes);
		String base64Creds = new String(base64CredsBytes);

		HttpHeaders headers = new HttpHeaders();
		headers.add("Authorization", "Basic " + base64Creds);
		HttpEntity<Apuesta> httpEntity = new HttpEntity<>(apuesta, headers);
		
		CloseableHttpClient httpClient = HttpClients.custom().build();
		HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
		requestFactory.setHttpClient(httpClient);

		RestTemplate restTemplate = new RestTemplate(requestFactory);
		ResponseEntity<Object> response = null;
		
		try {
			response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, Object.class);
		} catch (HttpClientErrorException e) {
			flashService.setError(e.getResponseBodyAsString());
		}
		
		if (response != null) {
			flashService.setSuccess("Apuesta realizada correctamente");
		}
	}
	
	return "redirect:" + redirect;
}
 
開發者ID:arubioVK,項目名稱:La-Apostada,代碼行數:42,代碼來源:ApuestaController.java

示例11: restTemplate

import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; //導入方法依賴的package包/類
@Bean
public RestTemplate restTemplate(HttpClient httpClient) {
	HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    requestFactory.setHttpClient(httpClient);
    return new RestTemplate(requestFactory);
}
 
開發者ID:SeldonIO,項目名稱:seldon-core,代碼行數:7,代碼來源:RestTemplateConfig.java


注:本文中的org.springframework.http.client.HttpComponentsClientHttpRequestFactory.setHttpClient方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。