package org.dontpanic.spanners.springmvc.config;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.ribbon.RibbonClientHttpRequestFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Configure the Rest client
 * Created by stevie on 09/09/16.
 */
@Configuration
@EnableDiscoveryClient
public class RestClientConfig {

    private Logger logger = Logger.getLogger(RestClientConfig.class);

    @Autowired(required = false)
    private RibbonClientHttpRequestFactory ribbonRequestFactory;

    /**
     * Use Ribbon load balancer to resolve service endpoints
     */
    @Bean
    public RestTemplateBuilder restTemplateBuilder() {

        RestTemplateBuilder builder = new RestTemplateBuilder();
        if (ribbonRequestFactory != null) {
            builder = builder.requestFactory(ribbonRequestFactory);
        } else {
            logger.warn("Ribbon Http client disabled. Service endpoints will not be resolved by Eureka.");
        }
        return builder;
    }

}

@@ -54,94 +54,198 @@
 ort 
-org.apache.log4j.Logger;%0Aimport org.springframework.beans.factory.annotation.Autowired
+com.netflix.client.http.HttpRequest;%0Aimport org.springframework.boot.autoconfigure.condition.ConditionalOnClass;%0Aimport org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
 ;%0Aim
@@ -297,21 +297,24 @@
 Template
-Build
+Customiz
 er;%0Aimpo
@@ -579,501 +579,690 @@
 on;%0A
-%0A/**%0A * Configure the Rest client%0A * Created by stevie on 09/09/16.%0A */%0A@Configuration%0A@EnableDiscoveryClient%0Apublic class RestClientConfig %7B%0A%0A    private Logger logger = Logger.getLogger(RestClientConfig.class);%0A%0A    @Autowired(required = false)%0A    private RibbonClientHttpRequestFactory ribbonRequestFactory;%0A%0A    /**%0A     * Use Ribbon load balancer to resolve service endpoints%0A     */%0A    @Bean%0A    public RestTemplateBuilder restTemplateBuilder() %7B%0A%0A        RestTemplateBuilder builder =
+import org.springframework.web.client.RestTemplate;%0A%0A/**%0A * Configure the Rest client%0A *%0A * Implementation based on spring-cloud-netflix-core RibbonClientConfig.%0A *%0A * Created by stevie on 09/09/16.%0A */%0A@Configuration%0A@ConditionalOnClass(HttpRequest.class)%0A@ConditionalOnProperty(value = %22ribbon.http.client.enabled%22, matchIfMissing = false)%0A@EnableDiscoveryClient%0Apublic class RestClientConfig %7B%0A%0A    /**%0A     * Customize the RestTemplate to use Ribbon load balancer to resolve service endpoints%0A     */%0A    @Bean%0A    public RestTemplateCustomizer ribbonClientRestTemplateCustomizer(%0A            final RibbonClientHttpRequestFactory ribbonClientHttpRequestFactory) %7B%0A        return
  new
@@ -1278,18 +1278,22 @@
 late
-Build
+Customiz
 er()
-;
+ %7B
 %0A   
@@ -1301,236 +1301,169 @@
     
-if (ribbonRequestFactory != null) %7B%0A            builder = builder.requestFactory(ribbonRequestFactory);%0A        %7D else %7B%0A            logger.warn(%22Ribbon Http client disabled. Service endpoints will not be resolved by Eureka.%22);%0A
+    @Override%0A            public void customize(RestTemplate restTemplate) %7B%0A                restTemplate.setRequestFactory(ribbonClientHttpRequestFactory);%0A    
     
@@ -1480,22 +1480,9 @@
     
-return builder
+%7D
 ;%0A  

Configure RestTemplateCustomizer bean to provide ribbon client request factory to rest template