Skip to content

Commit

Permalink
Timeout på eksterne requester
Browse files Browse the repository at this point in the history
  • Loading branch information
rinnan17 committed Mar 4, 2024
1 parent 0eafafc commit a8306fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/kotlin/no/nav/bidrag/grunnlag/BidragGrunnlagConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ import no.nav.bidrag.grunnlag.consumer.pensjon.PensjonConsumer
import no.nav.bidrag.grunnlag.consumer.skattegrunnlag.SigrunConsumer
import no.nav.bidrag.grunnlag.service.SecurityTokenService
import no.nav.security.token.support.spring.api.EnableJwtTokenValidation
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder
import org.apache.hc.core5.http.io.SocketConfig
import org.apache.hc.core5.util.Timeout
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.web.client.RootUriTemplateHandler
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.Scope
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory
import org.springframework.http.client.observation.DefaultClientRequestObservationConvention
import org.springframework.retry.annotation.EnableRetry

Expand Down Expand Up @@ -67,6 +72,13 @@ class BidragGrunnlagConfig {
@Scope("prototype")
fun restTemplate(): HttpHeaderRestTemplate {
val httpHeaderRestTemplate = HttpHeaderRestTemplate()

val sc = SocketConfig.custom().setSoTimeout(Timeout.ofSeconds(30)).build()
val pb = PoolingHttpClientConnectionManagerBuilder.create().setDefaultSocketConfig(sc).build()
val connectionManager = HttpClientBuilder.create().setConnectionManager(pb).build()
val requestFactory = HttpComponentsClientHttpRequestFactory(connectionManager)
httpHeaderRestTemplate.requestFactory = requestFactory

httpHeaderRestTemplate.addHeaderGenerator(CorrelationIdFilter.CORRELATION_ID_HEADER) { CorrelationId.fetchCorrelationIdForThread() }
return httpHeaderRestTemplate
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class HentGrunnlagService(
}

is RestResponse.Failure -> {
LOGGER.warn("Feil ved kall til bidrag-person for å hente historiske identer ${response.statusCode}")
SECURE_LOGGER.warn("Feil ved kall til bidrag-person for å hente historiske identer for ident $personId. Respons = $response")
listOf(HistoriskIdent(personId, false))
}
Expand Down

0 comments on commit a8306fb

Please sign in to comment.