Add configuration and properties
This commit is contained in:
parent
7f8c17a938
commit
e1a10dd039
|
|
@ -0,0 +1,7 @@
|
|||
package ru.touchin.push.message.provider.hpk
|
||||
|
||||
import org.springframework.context.annotation.Import
|
||||
import ru.touchin.push.message.provider.hpk.configurations.PushMessageProviderHpkConfiguration
|
||||
|
||||
@Import(value = [PushMessageProviderHpkConfiguration::class])
|
||||
annotation class EnablePushMessageProviderHpk
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package ru.touchin.push.message.provider.hpk.configurations
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import org.springframework.beans.factory.annotation.Qualifier
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
|
||||
import org.springframework.cache.CacheManager
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache
|
||||
import org.springframework.cache.support.SimpleCacheManager
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.ComponentScan
|
||||
import org.springframework.context.annotation.Import
|
||||
import ru.touchin.push.message.provider.configurations.PushMessageProviderConfiguration
|
||||
import ru.touchin.push.message.provider.hpk.services.HmsOauthAccessTokenCacheServiceImpl.Companion.HMS_CLIENT_SERVICE_CACHE_KEY
|
||||
|
||||
@ComponentScan("ru.touchin.push.message.provider.hpk")
|
||||
@ConfigurationPropertiesScan(basePackages = ["ru.touchin.push.message.provider.hpk"])
|
||||
@Import(value = [PushMessageProviderConfiguration::class])
|
||||
class PushMessageProviderHpkConfiguration {
|
||||
|
||||
@Bean
|
||||
@Qualifier("push-message-provider.hpk.webclient-objectmapper")
|
||||
fun webclientObjectMapper(): ObjectMapper {
|
||||
return jacksonObjectMapper()
|
||||
.registerModule(JavaTimeModule())
|
||||
.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Qualifier("push-message-provider.hpk.client-objectmapper")
|
||||
fun clientObjectMapper(): ObjectMapper {
|
||||
return jacksonObjectMapper()
|
||||
.registerModule(JavaTimeModule())
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_NULL)
|
||||
.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@Qualifier("push-message-provider.hpk.webclient-cachemanager")
|
||||
fun cacheManager(): CacheManager {
|
||||
return SimpleCacheManager().also {
|
||||
it.setCaches(
|
||||
listOf(
|
||||
ConcurrentMapCache(HMS_CLIENT_SERVICE_CACHE_KEY)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package ru.touchin.push.message.provider.hpk.properties
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties
|
||||
import org.springframework.boot.context.properties.ConstructorBinding
|
||||
import java.net.URL
|
||||
import java.time.Duration
|
||||
|
||||
@ConstructorBinding
|
||||
@ConfigurationProperties(prefix = "push-message-provider.hpk")
|
||||
data class HpkProperties(
|
||||
val webServices: WebServices,
|
||||
) {
|
||||
|
||||
class WebServices(
|
||||
val clientId: String,
|
||||
val oauth: Oauth,
|
||||
val hpk: Hpk,
|
||||
)
|
||||
|
||||
class Oauth(
|
||||
val clientSecret: String,
|
||||
url: URL,
|
||||
http: Http,
|
||||
ssl: Ssl?,
|
||||
) : WebService(
|
||||
url = url,
|
||||
http = http,
|
||||
ssl = ssl,
|
||||
)
|
||||
|
||||
class Hpk(
|
||||
url: URL,
|
||||
http: Http,
|
||||
ssl: Ssl?,
|
||||
) : WebService(
|
||||
url = url,
|
||||
http = http,
|
||||
ssl = ssl,
|
||||
)
|
||||
|
||||
open class WebService(
|
||||
val url: URL,
|
||||
val http: Http,
|
||||
val ssl: Ssl?,
|
||||
)
|
||||
|
||||
class Http(
|
||||
val readTimeout: Duration,
|
||||
val writeTimeout: Duration,
|
||||
val connectionTimeout: Duration,
|
||||
)
|
||||
|
||||
class Ssl(
|
||||
val handshakeTimeout: Duration,
|
||||
val notifyFlushTimeout: Duration,
|
||||
val notifyReadTimeout: Duration,
|
||||
)
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue