Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down Expand Up @@ -196,12 +200,6 @@
</dependency>

<!-- Runtime dependencies -->
<dependency>
<!-- Used by RestTemplate -->
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
Expand Down
27 changes: 25 additions & 2 deletions src/main/java/org/gridsuite/study/server/RestTemplateConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import com.powsybl.sensitivity.json.SensitivityJsonModule;
import com.powsybl.shortcircuit.json.ShortCircuitAnalysisJsonModule;
import com.powsybl.timeseries.json.TimeSeriesJsonModule;
import org.apache.hc.client5.http.classic.HttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
Expand All @@ -31,9 +35,28 @@
@Configuration
public class RestTemplateConfig {

@Value("${http.client.pool.max-connections:500}")
private int httpClientPoolMaxConnections;

@Value("${http.client.pool.max-connections-per-host:200}")
private int httpClientPoolMaxConnectionsPerHost;

@Bean
public HttpClient httpClient() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
// By default, it's limited to 20 connections and 5 connections per host which is very too low for study-server needs
connectionManager.setMaxTotal(httpClientPoolMaxConnections);
connectionManager.setDefaultMaxPerRoute(httpClientPoolMaxConnectionsPerHost);

return HttpClients.custom()
.setConnectionManager(connectionManager)
.build();
}

@Bean
public RestTemplate restTemplate() {
final RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
public RestTemplate restTemplate(HttpClient httpClient) {
// We're using HttpComponentsClientHttpRequestFactory from apache httpclient5 to handle properly HTTP PATCH method
final RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));

//find and replace Jackson message converter with our own
for (int i = 0; i < restTemplate.getMessageConverters().size(); i++) {
Expand Down