Search in sources :

Example 1 with DisabledSslClientHttpRequestFactory

use of com.qaprosoft.hockeyapp.http.resttemplate.ssl.DisabledSslClientHttpRequestFactory in project carina by qaprosoft.

the class RestTemplateBuilder method build.

public RestTemplate build() {
    if (!isUseDefaultJsonMessageConverter) {
        HttpMessageConverter<?> httpMessageConverter = Iterables.tryFind(restTemplate.getMessageConverters(), new Predicate<HttpMessageConverter<?>>() {

            @Override
            public boolean apply(HttpMessageConverter<?> input) {
                return input instanceof MappingJackson2HttpMessageConverter;
            }
        }).orNull();
        restTemplate.getMessageConverters().remove(httpMessageConverter);
    }
    restTemplate.getMessageConverters().addAll(httpMessageConverters);
    if (isDisableSslChecking) {
        restTemplate.setRequestFactory(new DisabledSslClientHttpRequestFactory());
    }
    if (isUseBasicAuth) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuthUsername, basicAuthPassword));
        HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
        restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
    }
    return restTemplate;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) AbstractHttpMessageConverter(org.springframework.http.converter.AbstractHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) DisabledSslClientHttpRequestFactory(com.qaprosoft.hockeyapp.http.resttemplate.ssl.DisabledSslClientHttpRequestFactory) Predicate(com.google.common.base.Predicate) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

Predicate (com.google.common.base.Predicate)1 DisabledSslClientHttpRequestFactory (com.qaprosoft.hockeyapp.http.resttemplate.ssl.DisabledSslClientHttpRequestFactory)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 HttpClient (org.apache.http.client.HttpClient)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)1 AbstractHttpMessageConverter (org.springframework.http.converter.AbstractHttpMessageConverter)1 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1