Skip to content

Commit f8a3620

Browse files
authored
Merge pull request #61 from ActiveCampaign/http-client-updates
Http client updates
2 parents dff32c1 + 9b4cd11 commit f8a3620

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.11.1
4+
5+
* small updated to http client connection settings
6+
37
## 1.11.0
48

59
* Add data removal endpoints

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</developers>
2424

2525
<properties>
26-
<postmark.version>1.11.0</postmark.version>
26+
<postmark.version>1.11.1</postmark.version>
2727
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2828
<java.version>1.8</java.version>
2929
<jackson.minimum.version>2.9.7</jackson.minimum.version>
@@ -51,7 +51,7 @@
5151
<dependency>
5252
<groupId>org.apache.httpcomponents.client5</groupId>
5353
<artifactId>httpclient5</artifactId>
54-
<version>5.2.1</version>
54+
<version>5.3</version>
5555
</dependency>
5656

5757
<!-- Serialization to JSON -->

src/main/java/com/postmarkapp/postmark/client/HttpClient.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import org.apache.hc.client5.http.config.RequestConfig;
44
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
55
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
6-
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
76
import org.apache.hc.core5.http.ClassicHttpRequest;
87
import org.apache.hc.core5.http.ContentType;
8+
import org.apache.hc.core5.http.HttpEntity;
99
import org.apache.hc.core5.http.io.entity.EntityUtils;
1010
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
1111
import org.apache.hc.core5.util.Timeout;
@@ -36,21 +36,17 @@ public enum DEFAULTS {
3636
// client configuration options like timeouts, forwarding ..
3737
private RequestConfig.Builder clientConfigBuilder;
3838

39-
private final PoolingHttpClientConnectionManager connectionManager;
40-
4139
private boolean secureConnection = true;
4240

4341
public HttpClient(Map<String,Object> headers, int connectTimeoutSeconds, int readTimeoutSeconds) {
4442
this.headers = headers;
4543
this.clientConfigBuilder = RequestConfig
4644
.custom()
4745
.setConnectTimeout(Timeout.ofSeconds(connectTimeoutSeconds))
46+
.setConnectionRequestTimeout(Timeout.ofSeconds(connectTimeoutSeconds))
47+
.setConnectionKeepAlive(Timeout.ofSeconds(connectTimeoutSeconds))
4848
.setResponseTimeout(Timeout.ofSeconds(readTimeoutSeconds));
4949

50-
this.connectionManager = new PoolingHttpClientConnectionManager();
51-
connectionManager.setMaxTotal(100);
52-
connectionManager.setDefaultMaxPerRoute(25);
53-
5450
this.client = buildClient();
5551
}
5652

@@ -89,7 +85,14 @@ public ClientResponse execute(REQUEST_TYPES requestType, String url, String data
8985

9086
return client.execute(
9187
request,
92-
response -> new ClientResponse(response.getCode(), EntityUtils.toString(response.getEntity())));
88+
response -> {
89+
final HttpEntity entity = response.getEntity();
90+
int code = response.getCode();
91+
String body = EntityUtils.toString(response.getEntity());
92+
EntityUtils.consume(entity);
93+
94+
return new ClientResponse(code, body);
95+
});
9396
}
9497

9598
/**
@@ -154,7 +157,6 @@ private CloseableHttpClient buildClient() {
154157
return HttpClientBuilder
155158
.create()
156159
.setDefaultRequestConfig(clientConfigBuilder.build())
157-
.setConnectionManager(connectionManager)
158160
.build();
159161
}
160162

src/test/java/integration/MessageStreamsTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ void edit() throws PostmarkException, IOException {
6363

6464
@Test
6565
void archive() throws PostmarkException, IOException {
66-
String streamId = "bulk-test-stream-1201";
66+
String streamId = "test-bulk-test-stream-1201";
6767
MessageStreams messages = client.getMessageStreams(Parameters.init().build("messageStreamType", "all")
6868
.build("includeArchivedStreams", "true"));
6969

7070
MessageStream foundStream = findMessageStream(streamId);
7171

7272
if (foundStream == null) {
73-
client.createMessageStream(new MessageStream(streamId, streamId,"Broadcasts"));
73+
MessageStream messageStream = new MessageStream(streamId, streamId,"Broadcasts");
74+
client.createMessageStream(messageStream);
7475
}
75-
7676
else if (foundStream.getArchivedAt() != null) {
7777
client.unarchiveMessageStream(streamId);
7878
}

src/test/java/integration/MessageTest.java

-8
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ void send() throws PostmarkException, IOException {
3131
assertEquals(response.getMessageId().length(),36);
3232
}
3333

34-
@Test
35-
void invalidMessagetoSend() throws PostmarkException, IOException {
36-
Message message = new Message("[email protected]", null, "Hello from Postmark!", "Hello body");
37-
38-
Throwable exception = assertThrows(InvalidMessageException.class, () -> client.deliverMessage(message));
39-
assertEquals("Zero recipients specified", exception.getMessage());
40-
}
41-
4234
@Test
4335
void invalidApiToken() throws PostmarkException, IOException {
4436
ApiClient client = Postmark.getApiClient("1991892", true);

0 commit comments

Comments
 (0)