Example usage for org.springframework.boot.web.client RestTemplateCustomizer RestTemplateCustomizer

List of usage examples for org.springframework.boot.web.client RestTemplateCustomizer RestTemplateCustomizer

Introduction

In this page you can find the example usage for org.springframework.boot.web.client RestTemplateCustomizer RestTemplateCustomizer.

Prototype

RestTemplateCustomizer

Source Link

Usage

From source file:org.springframework.cloud.contract.wiremock.WireMockRestTemplateConfiguration.java

@Bean
@ConditionalOnClass(SSLContextBuilder.class)
public RestTemplateCustomizer restTemplateCustomizer() {
    return new RestTemplateCustomizer() {
        @Override//  w  ww .  j  av  a2 s .  c  o m
        public void customize(RestTemplate restTemplate) {
            HttpComponentsClientHttpRequestFactory factory = (HttpComponentsClientHttpRequestFactory) restTemplate
                    .getRequestFactory();
            factory.setHttpClient(createSslHttpClient());
        }

        private HttpClient createSslHttpClient() {
            try {
                SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                        new SSLContextBuilder().loadTrustMaterial(null, TrustSelfSignedStrategy.INSTANCE)
                                .build(),
                        NoopHostnameVerifier.INSTANCE);
                return HttpClients.custom().setSSLSocketFactory(socketFactory).build();
            } catch (Exception ex) {
                throw new IllegalStateException("Unable to create SSL HttpClient", ex);
            }
        }
    };
}