-
Notifications
You must be signed in to change notification settings - Fork 43
/
BeanConfig.kt
46 lines (41 loc) · 1.77 KB
/
BeanConfig.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.dreamexposure.discal.core.config
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
import discord4j.common.JacksonResources
import io.micrometer.core.instrument.binder.okhttp3.OkHttpObservationInterceptor
import io.micrometer.observation.ObservationRegistry
import okhttp3.OkHttpClient
import org.dreamexposure.discal.core.serializers.DurationMapper
import org.dreamexposure.discal.core.serializers.SnowflakeMapper
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary
import org.springframework.web.reactive.result.method.annotation.RequestMappingHandlerMapping
@Configuration
class BeanConfig {
@Bean
@Primary
fun objectMapper(): ObjectMapper {
// Use d4j's object mapper
return JacksonResources.create().objectMapper
.registerKotlinModule()
.registerModule(JavaTimeModule())
.registerModule(SnowflakeMapper())
.registerModule(DurationMapper())
}
@Bean
fun handlerMapping(): RequestMappingHandlerMapping {
return RequestMappingHandlerMapping()
}
@Bean
fun httpClient(registry: ObservationRegistry): OkHttpClient {
val interceptor = OkHttpObservationInterceptor.builder(registry, "okhttp.requests")
// This can lead to tag cardinality explosion as it doesn't use uri patterns, should investigate options for that one day
.uriMapper { "${it.method} ${it.url.host}${it.url.encodedPath}" }
.build()
return OkHttpClient.Builder()
.addInterceptor(interceptor)
.build()
}
}