use of org.springframework.http.client.support.BasicAuthorizationInterceptor in project tutorials by eugenp.
the class RestTemplateFactory method afterPropertiesSet.
@Override
public void afterPropertiesSet() {
HttpHost host = new HttpHost("localhost", 8082, "http");
final ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactoryBasicAuth(host);
restTemplate = new RestTemplate(requestFactory);
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor("user1", "user1Pass"));
}
use of org.springframework.http.client.support.BasicAuthorizationInterceptor in project spring-cloud-netflix by spring-cloud.
the class RestTemplateTransportClientFactory method restTemplate.
private RestTemplate restTemplate(String serviceUrl) {
RestTemplate restTemplate = new RestTemplate();
try {
URI serviceURI = new URI(serviceUrl);
if (serviceURI.getUserInfo() != null) {
String[] credentials = serviceURI.getUserInfo().split(":");
if (credentials.length == 2) {
restTemplate.getInterceptors().add(new BasicAuthorizationInterceptor(credentials[0], credentials[1]));
}
}
} catch (URISyntaxException ignore) {
}
restTemplate.getMessageConverters().add(0, mappingJacksonHttpMessageConverter());
return restTemplate;
}
Aggregations