Skip to content

Commit

Permalink
#111 - config for timeout with high default value
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Dec 20, 2023
1 parent c3f291b commit 865fe00
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.avni_integration_service.avni.domain.auth.IdpDetailsResponse;
import org.avni_integration_service.util.ObjectJsonMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
Expand All @@ -20,6 +21,7 @@
@Component
public class AvniHttpClient {
@Autowired
@Qualifier("AvniRestTemplate")
private RestTemplate restTemplate;

private static final Logger logger = Logger.getLogger(AvniHttpClient.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.avni_integration_service.avni.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

@Configuration
public class AvniBeanConfiguration {
private final RestTemplate restTemplate;

@Value("${avni.httpClient.timeout}")
private int avniHttpClientTimeout;

@Autowired
public AvniBeanConfiguration(Environment environment, RestTemplateBuilder restTemplateBuilder) {
Duration timeout = Duration.ofSeconds(avniHttpClientTimeout);
restTemplate = restTemplateBuilder.setConnectTimeout(timeout)
.setReadTimeout(timeout)
.build();
}

@Bean("AvniRestTemplate")
public RestTemplate avniRestTemplate() {
return restTemplate;
}
}
1 change: 1 addition & 0 deletions avni/src/main/resources/avni-application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ avni.db.port=${AVNI_DB_PORT:5432}
avni.impl_org.db.user=${AVNI_IMPL_DB_USER:dummy}
avni.impl.user.id=${AVNI_IMPL_USER_ID:-1}
app.config.tx.rollback=${AVNI_DB_TX_ROLLBACK:true}
avni.httpClient.timeout=${AVNI_HTTP_CLIENT_TIMEOUT:120}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.avni_integration_service.goonj.config.GoonjConfig;
import org.avni_integration_service.goonj.config.GoonjContextProvider;
import org.avni_integration_service.goonj.domain.AuthResponse;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -33,7 +34,7 @@ public class TokenService {
@Value("${goonj.sf.tokenExpiry}")
private int tokenExpiry;

public TokenService(RestTemplate restTemplate, GoonjContextProvider goonjContextProvider) {
public TokenService(@Qualifier("UtilRestTemplate") RestTemplate restTemplate, GoonjContextProvider goonjContextProvider) {
this.restTemplate = restTemplate;
this.goonjContextProvider = goonjContextProvider;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.avni_integration_service.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -12,19 +13,15 @@

@Configuration
public class BeanConfiguration {
private final RestTemplate restTemplate;
private final RestTemplate utilRestTemplate;

@Autowired
public BeanConfiguration(Environment environment, RestTemplateBuilder restTemplateBuilder) {
Duration timeout = Duration.ofSeconds(20);
restTemplate = restTemplateBuilder.setConnectTimeout(timeout)
.setReadTimeout(timeout)
.build();
utilRestTemplate = restTemplateBuilder.build();
}

@Bean
@Primary
public RestTemplate restTemplate() {
return restTemplate;
@Bean("UtilRestTemplate")
public RestTemplate utilRestTemplate() {
return utilRestTemplate;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.avni_integration_service.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
Expand All @@ -21,7 +22,7 @@ public class HealthCheckService {
private String healthCheckPingKey;

@Autowired
public HealthCheckService(RestTemplate restTemplate) {
public HealthCheckService(@Qualifier("UtilRestTemplate") RestTemplate restTemplate) {
this.restTemplate = restTemplate;
}

Expand Down

0 comments on commit 865fe00

Please sign in to comment.