本文整理汇总了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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}