Skip to content

Commit

Permalink
http client dependency cleanup and fine tuning connection performance
Browse files Browse the repository at this point in the history
  • Loading branch information
ibalosh committed Mar 28, 2023
1 parent 21a6bba commit a398984
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 1.10.21

* updated default HTTP client connection settings
* adjusted HTTP client library package used

## 1.10.2

* updated HTTP client data requests issue with unicode characters
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</developers>

<properties>
<postmark.version>1.10.2</postmark.version>
<postmark.version>1.10.21</postmark.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<jackson.minimum.version>2.9.7</jackson.minimum.version>
Expand All @@ -50,7 +50,7 @@

<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5-fluent</artifactId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
</dependency>

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/postmarkapp/postmark/client/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.EntityUtils;
Expand Down Expand Up @@ -35,6 +36,8 @@ public enum DEFAULTS {
// client configuration options like timeouts, forwarding ..
private RequestConfig.Builder clientConfigBuilder;

private final PoolingHttpClientConnectionManager connectionManager;

private boolean secureConnection = true;

public HttpClient(Map<String,Object> headers, int connectTimeoutSeconds, int readTimeoutSeconds) {
Expand All @@ -44,6 +47,10 @@ public HttpClient(Map<String,Object> headers, int connectTimeoutSeconds, int rea
.setConnectTimeout(Timeout.ofSeconds(connectTimeoutSeconds))
.setResponseTimeout(Timeout.ofSeconds(readTimeoutSeconds));

this.connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(100);
connectionManager.setDefaultMaxPerRoute(25);

this.client = buildClient();
}

Expand Down Expand Up @@ -144,7 +151,11 @@ public CloseableHttpClient getClient() {
* @return initialized HTTP client
*/
private CloseableHttpClient buildClient() {
return HttpClientBuilder.create().setDefaultRequestConfig(clientConfigBuilder.build()).build();
return HttpClientBuilder
.create()
.setDefaultRequestConfig(clientConfigBuilder.build())
.setConnectionManager(connectionManager)
.build();
}

/**
Expand Down

0 comments on commit a398984

Please sign in to comment.