mirror of
https://github.com/2martens/tsw-timetable.git
synced 2026-10-17 16:06:51 +02:00
fix: Use restClient in RestHealthIndicator
This commit is contained in:
+22
@@ -3,11 +3,15 @@ package de.twomartens.support.configuration
|
|||||||
import de.twomartens.support.interceptor.HeaderInterceptorRest
|
import de.twomartens.support.interceptor.HeaderInterceptorRest
|
||||||
import de.twomartens.support.interceptor.LoggingInterceptorRest
|
import de.twomartens.support.interceptor.LoggingInterceptorRest
|
||||||
import de.twomartens.support.property.RestTemplateTimeoutProperties
|
import de.twomartens.support.property.RestTemplateTimeoutProperties
|
||||||
|
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder
|
||||||
|
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.http.client.ClientHttpRequestFactory
|
||||||
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter
|
import org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter
|
||||||
import org.springframework.web.client.RestClient
|
import org.springframework.web.client.RestClient
|
||||||
|
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
open class RestClientConfiguration {
|
open class RestClientConfiguration {
|
||||||
@Bean("restClient")
|
@Bean("restClient")
|
||||||
@@ -21,4 +25,22 @@ open class RestClientConfiguration {
|
|||||||
.requestInterceptors { listOf(headerInterceptorRest, loggingInterceptor) }
|
.requestInterceptors { listOf(headerInterceptorRest, loggingInterceptor) }
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean("restClientRestHealthIndicator")
|
||||||
|
open fun restClientRestHealthIndicator(
|
||||||
|
headerInterceptorRest: HeaderInterceptorRest,
|
||||||
|
restTemplateTimeoutProperties: RestTemplateTimeoutProperties
|
||||||
|
): RestClient {
|
||||||
|
return RestClient.builder()
|
||||||
|
.requestInterceptors { listOf(headerInterceptorRest) }
|
||||||
|
.requestFactory(customRequestFactory(restTemplateTimeoutProperties))
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun customRequestFactory(restTemplateTimeoutProperties: RestTemplateTimeoutProperties): ClientHttpRequestFactory {
|
||||||
|
val settings: ClientHttpRequestFactorySettings = ClientHttpRequestFactorySettings.defaults()
|
||||||
|
.withConnectTimeout(restTemplateTimeoutProperties.connectionRestTemplateTimeoutInMillis)
|
||||||
|
.withReadTimeout(restTemplateTimeoutProperties.readTimeoutRestTemplateInMillis)
|
||||||
|
return ClientHttpRequestFactoryBuilder.detect().build(settings)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -7,7 +7,7 @@ import org.springframework.boot.actuate.health.HealthIndicator
|
|||||||
import org.springframework.boot.actuate.health.Status
|
import org.springframework.boot.actuate.health.Status
|
||||||
import org.springframework.boot.autoconfigure.web.ServerProperties
|
import org.springframework.boot.autoconfigure.web.ServerProperties
|
||||||
import org.springframework.stereotype.Component
|
import org.springframework.stereotype.Component
|
||||||
import org.springframework.web.client.RestTemplate
|
import org.springframework.web.client.RestClient
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ import java.time.Clock
|
|||||||
class RestHealthIndicator(
|
class RestHealthIndicator(
|
||||||
clock: Clock, interceptor: HeaderInterceptorRest,
|
clock: Clock, interceptor: HeaderInterceptorRest,
|
||||||
serverProperties: ServerProperties,
|
serverProperties: ServerProperties,
|
||||||
private val restTemplateRestHealthIndicator: RestTemplate,
|
private val restClientRestHealthIndicator: RestClient,
|
||||||
private val serviceProperties: HealthCheckProperties
|
private val serviceProperties: HealthCheckProperties
|
||||||
) : AbstractHealthIndicator(clock, Preparable { interceptor.markAsHealthCheck() }), HealthIndicator {
|
) : AbstractHealthIndicator(clock, Preparable { interceptor.markAsHealthCheck() }), HealthIndicator {
|
||||||
private val randomizer = SecureRandom()
|
private val randomizer = SecureRandom()
|
||||||
|
|||||||
Reference in New Issue
Block a user