I had this Java code: ``` @Bean @Condition...
# announcements
d
I had this Java code:
Copy code
@Bean
    @ConditionalOnProperty( prefix = "proxy", name = "enabled", havingValue = "true")
    public RestTemplateCustomizer restTemplateCustomizer() {
        return restTemplate -> {
            var proxy = new HttpHost(host, port, scheme);
            var httpClient = HttpClientBuilder.create().setRoutePlanner(new DefaultProxyRoutePlanner(proxy)).build();
            restTemplate.setRequestFactory( new HttpComponentsClientHttpRequestFactory(httpClient));
        };
    }
where RestTemplateCustomizer is a functional interface. But I have trouble writing this in Kotlin
s
what does the
RestTemplateCustomizer
definition look like?
d
ah got it to work
Copy code
@Bean
    @ConditionalOnProperty(prefix = "proxy", name = arrayOf("enabled"), havingValue = "true")
    fun restTemplateCustomizer(): RestTemplateCustomizer {
        return RestTemplateCustomizer { restTemplate ->
            val proxy = HttpHost(host!!, port, scheme)
            val httpClient = HttpClientBuilder.create().setRoutePlanner(DefaultProxyRoutePlanner(proxy)).build()
            restTemplate.setRequestFactory(HttpComponentsClientHttpRequestFactory(httpClient))
        }
    }
c
Or you could do this:
Copy code
fun restTemplateCustomizer(): RestTemplateCustomizer = RestTemplateCustomizer { restTemplate ->
	val proxy = HttpHost(host, port, scheme)
	val httpClient = HttpClientBuilder.create().setRoutePlanner(DefaultProxyRoutePlanner(proxy)).build()
	restTemplate.setRequestFactory(HttpComponentsClientHttpRequestFactory(httpClient))
}
or even
Copy code
fun restTemplateCustomizer() = RestTemplateCustomizer { restTemplate ->
	val proxy = HttpHost(host, port, scheme)
	val httpClient = HttpClientBuilder.create().setRoutePlanner(DefaultProxyRoutePlanner(proxy)).build()
	restTemplate.setRequestFactory(HttpComponentsClientHttpRequestFactory(httpClient))
}