All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.autoconfigure.bootstrap.httpclient.HttpClientAutoConfiguration Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
package org.zodiac.autoconfigure.bootstrap.httpclient;

import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.core.httpclient.ahc.ApacheHttpClientConnectionManagerFactory;
import org.zodiac.core.httpclient.ahc.ApacheHttpClientFactory;
import org.zodiac.core.httpclient.ahc.DefaultApacheHttpClientConnectionManagerFactory;
import org.zodiac.core.httpclient.ahc.DefaultApacheHttpClientFactory;
import org.zodiac.core.httpclient.okhttp.DefaultOkHttpClientConnectionPoolFactory;
import org.zodiac.core.httpclient.okhttp.DefaultOkHttpClientFactory;
import org.zodiac.core.httpclient.okhttp.OkHttpClientConnectionPoolFactory;
import org.zodiac.core.httpclient.okhttp.OkHttpClientFactory;

@SpringBootConfiguration
public class HttpClientAutoConfiguration {

    public HttpClientAutoConfiguration() {
        super();
    }

    @SpringBootConfiguration
    @ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SPRING_HTTP_CLIENT_APACHE_HTTPCLIENT_ENABLED, havingValue = "true", matchIfMissing = true)
    @ConditionalOnClass(value = {org.apache.http.client.HttpClient.class})
    static class ApacheHttpClientConfiguration {

        @Bean
        @ConditionalOnMissingBean
        protected ApacheHttpClientConnectionManagerFactory connManFactory() {
            return new DefaultApacheHttpClientConnectionManagerFactory();
        }

        @Bean
        @ConditionalOnMissingBean
        protected org.apache.http.impl.client.HttpClientBuilder apacheHttpClientBuilder() {
            return org.apache.http.impl.client.HttpClientBuilder.create();
        }

        @Bean
        @ConditionalOnMissingBean
        protected ApacheHttpClientFactory
            apacheHttpClientFactory(org.apache.http.impl.client.HttpClientBuilder builder) {
            return new DefaultApacheHttpClientFactory(builder);
        }

    }

    @SpringBootConfiguration
    @ConditionalOnProperty(name = SystemPropertiesConstants.Zodiac.SPRING_HTTP_CLIENT_OKHTTP_ENABLED, havingValue = "true")
    @ConditionalOnClass(value = {okhttp3.OkHttpClient.class})
    static class OkHttpClientConfiguration {

        @Bean
        @ConditionalOnMissingBean
        protected OkHttpClientConnectionPoolFactory connPoolFactory() {
            return new DefaultOkHttpClientConnectionPoolFactory();
        }

        @Bean
        @ConditionalOnMissingBean
        protected okhttp3.OkHttpClient.Builder okHttpClientBuilder() {
            return new okhttp3.OkHttpClient.Builder();
        }

        @Bean
        @ConditionalOnMissingBean
        protected OkHttpClientFactory okHttpClientFactory(okhttp3.OkHttpClient.Builder builder) {
            return new DefaultOkHttpClientFactory(builder);
        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy