Search in sources :

Example 1 with HttpClientSdkFactory

use of com.netflix.spinnaker.kork.plugins.sdk.httpclient.HttpClientSdkFactory in project kork by spinnaker.

the class HttpClientSdkConfiguration method httpClientSdkFactory.

@Bean
public static SdkFactory httpClientSdkFactory(List<OkHttp3ClientFactory> okHttpClientFactories, Environment environment, Provider<Registry> registry) {
    OkHttpClientConfigurationProperties okHttpClientProperties = Binder.get(environment).bind("ok-http-client", Bindable.of(OkHttpClientConfigurationProperties.class)).orElse(new OkHttpClientConfigurationProperties());
    OkHttpMetricsInterceptorProperties okHttpMetricsInterceptorProperties = Binder.get(environment).bind("ok-http-client.interceptor", Bindable.of(OkHttpMetricsInterceptorProperties.class)).orElse(new OkHttpMetricsInterceptorProperties());
    List<OkHttp3ClientFactory> factories = new ArrayList<>(okHttpClientFactories);
    OkHttp3MetricsInterceptor okHttp3MetricsInterceptor = new OkHttp3MetricsInterceptor(registry, okHttpMetricsInterceptorProperties);
    factories.add(new DefaultOkHttp3ClientFactory(okHttp3MetricsInterceptor));
    OkHttp3ClientConfiguration config = new OkHttp3ClientConfiguration(okHttpClientProperties, okHttp3MetricsInterceptor);
    KotlinModule kotlinModule = new KotlinModule.Builder().build();
    // TODO(rz): It'd be nice to make this customizable, but I'm not sure how to do that without
    // bringing Jackson into the Plugin SDK (quite undesirable).
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new Jdk8Module());
    objectMapper.registerModule(new JavaTimeModule());
    objectMapper.registerModule(kotlinModule);
    objectMapper.disable(READ_DATE_TIMESTAMPS_AS_NANOSECONDS);
    objectMapper.disable(WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
    objectMapper.disable(FAIL_ON_UNKNOWN_PROPERTIES);
    objectMapper.disable(FAIL_ON_EMPTY_BEANS);
    objectMapper.setSerializationInclusion(NON_NULL);
    return new HttpClientSdkFactory(new CompositeOkHttpClientFactory(factories), environment, objectMapper, config);
}
Also used : CompositeOkHttpClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.CompositeOkHttpClientFactory) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) ArrayList(java.util.ArrayList) HttpClientSdkFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.HttpClientSdkFactory) Jdk8Module(com.fasterxml.jackson.datatype.jdk8.Jdk8Module) OkHttp3MetricsInterceptor(com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor) OkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.OkHttp3ClientFactory) DefaultOkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory) DefaultOkHttp3ClientFactory(com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory) KotlinModule(com.fasterxml.jackson.module.kotlin.KotlinModule) OkHttpClientConfigurationProperties(com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Bean(org.springframework.context.annotation.Bean)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Jdk8Module (com.fasterxml.jackson.datatype.jdk8.Jdk8Module)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 KotlinModule (com.fasterxml.jackson.module.kotlin.KotlinModule)1 HttpClientSdkFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.HttpClientSdkFactory)1 OkHttp3ClientFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.OkHttp3ClientFactory)1 CompositeOkHttpClientFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.CompositeOkHttpClientFactory)1 DefaultOkHttp3ClientFactory (com.netflix.spinnaker.kork.plugins.sdk.httpclient.internal.DefaultOkHttp3ClientFactory)1 OkHttp3MetricsInterceptor (com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor)1 OkHttpClientConfigurationProperties (com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties)1 ArrayList (java.util.ArrayList)1 Bean (org.springframework.context.annotation.Bean)1