org.zodiac.autoconfigure.okhttp.OkHttpAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.okhttp;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.zodiac.autoconfigure.web.condition.ConditionalOnWebRemoteEnabled;
import org.zodiac.autoconfigure.web.remote.WebRemoteProperties;
import org.zodiac.core.web.support.RestTemplateHeaderInterceptor;
import org.zodiac.okhttp.config.OkHttpConfigurer;
import org.zodiac.okhttp.logger.HttpLoggingInterceptor;
@SpringBootConfiguration
@ConditionalOnWebRemoteEnabled
@ConditionalOnClass(value = {okhttp3.OkHttpClient.class})
public class OkHttpAutoConfiguration extends OkHttpConfigurer {
private final WebRemoteProperties webRemoteProperties;
public OkHttpAutoConfiguration(WebRemoteProperties webRemoteProperties) {
this.webRemoteProperties = webRemoteProperties;
}
@Bean
@ConditionalOnMissingBean
protected HttpLoggingInterceptor loggingInterceptor() {
return super.loggingInterceptor(webRemoteProperties);
}
@Bean
@ConditionalOnMissingBean
protected okhttp3.ConnectionPool httpClientConnectionPool() {
return createOkHttpConnectionPool(webRemoteProperties);
}
@Bean
@ConditionalOnMissingBean
protected okhttp3.OkHttpClient okHttpClient(okhttp3.ConnectionPool connectionPool,
ObjectProvider interceptorsProvider) {
List interceptors = interceptorsProvider.stream().collect(Collectors.toList());
return createOkHttpClient(connectionPool, interceptors, webRemoteProperties);
}
@Bean
@ConditionalOnMissingBean
protected RestTemplateHeaderInterceptor requestHeaderInterceptor() {
return super.requestHeaderInterceptor();
}
}