diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d2dece..a1aec88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.11.1 + +* small updated to http client connection settings + ## 1.11.0 * Add data removal endpoints diff --git a/pom.xml b/pom.xml index 6dab4ac..ae3505c 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ - 1.11.0 + 1.11.1 UTF-8 1.8 2.9.7 @@ -51,7 +51,7 @@ org.apache.httpcomponents.client5 httpclient5 - 5.2.1 + 5.3 diff --git a/src/main/java/com/postmarkapp/postmark/client/HttpClient.java b/src/main/java/com/postmarkapp/postmark/client/HttpClient.java index 5f5bfa4..22815b0 100644 --- a/src/main/java/com/postmarkapp/postmark/client/HttpClient.java +++ b/src/main/java/com/postmarkapp/postmark/client/HttpClient.java @@ -3,9 +3,9 @@ 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.HttpEntity; import org.apache.hc.core5.http.io.entity.EntityUtils; import org.apache.hc.core5.http.io.support.ClassicRequestBuilder; import org.apache.hc.core5.util.Timeout; @@ -36,8 +36,6 @@ public enum DEFAULTS { // client configuration options like timeouts, forwarding .. private RequestConfig.Builder clientConfigBuilder; - private final PoolingHttpClientConnectionManager connectionManager; - private boolean secureConnection = true; public HttpClient(Map headers, int connectTimeoutSeconds, int readTimeoutSeconds) { @@ -45,12 +43,10 @@ public HttpClient(Map headers, int connectTimeoutSeconds, int rea this.clientConfigBuilder = RequestConfig .custom() .setConnectTimeout(Timeout.ofSeconds(connectTimeoutSeconds)) + .setConnectionRequestTimeout(Timeout.ofSeconds(connectTimeoutSeconds)) + .setConnectionKeepAlive(Timeout.ofSeconds(connectTimeoutSeconds)) .setResponseTimeout(Timeout.ofSeconds(readTimeoutSeconds)); - this.connectionManager = new PoolingHttpClientConnectionManager(); - connectionManager.setMaxTotal(100); - connectionManager.setDefaultMaxPerRoute(25); - this.client = buildClient(); } @@ -89,7 +85,14 @@ public ClientResponse execute(REQUEST_TYPES requestType, String url, String data return client.execute( request, - response -> new ClientResponse(response.getCode(), EntityUtils.toString(response.getEntity()))); + response -> { + final HttpEntity entity = response.getEntity(); + int code = response.getCode(); + String body = EntityUtils.toString(response.getEntity()); + EntityUtils.consume(entity); + + return new ClientResponse(code, body); + }); } /** @@ -154,7 +157,6 @@ private CloseableHttpClient buildClient() { return HttpClientBuilder .create() .setDefaultRequestConfig(clientConfigBuilder.build()) - .setConnectionManager(connectionManager) .build(); } diff --git a/src/test/java/integration/MessageStreamsTest.java b/src/test/java/integration/MessageStreamsTest.java index 1883ebe..456c07f 100644 --- a/src/test/java/integration/MessageStreamsTest.java +++ b/src/test/java/integration/MessageStreamsTest.java @@ -63,16 +63,16 @@ void edit() throws PostmarkException, IOException { @Test void archive() throws PostmarkException, IOException { - String streamId = "bulk-test-stream-1201"; + String streamId = "test-bulk-test-stream-1201"; MessageStreams messages = client.getMessageStreams(Parameters.init().build("messageStreamType", "all") .build("includeArchivedStreams", "true")); MessageStream foundStream = findMessageStream(streamId); if (foundStream == null) { - client.createMessageStream(new MessageStream(streamId, streamId,"Broadcasts")); + MessageStream messageStream = new MessageStream(streamId, streamId,"Broadcasts"); + client.createMessageStream(messageStream); } - else if (foundStream.getArchivedAt() != null) { client.unarchiveMessageStream(streamId); } diff --git a/src/test/java/integration/MessageTest.java b/src/test/java/integration/MessageTest.java index 8a00a4f..b523854 100644 --- a/src/test/java/integration/MessageTest.java +++ b/src/test/java/integration/MessageTest.java @@ -31,14 +31,6 @@ void send() throws PostmarkException, IOException { assertEquals(response.getMessageId().length(),36); } - @Test - void invalidMessagetoSend() throws PostmarkException, IOException { - Message message = new Message("from@example.com", null, "Hello from Postmark!", "Hello body"); - - Throwable exception = assertThrows(InvalidMessageException.class, () -> client.deliverMessage(message)); - assertEquals("Zero recipients specified", exception.getMessage()); - } - @Test void invalidApiToken() throws PostmarkException, IOException { ApiClient client = Postmark.getApiClient("1991892", true);