# HG changeset patch # User Sebastien Jodogne # Date 1547574419 -3600 # Node ID 58ea4ef84c924533eeb1f8dd27fa11140eb9f692 # Parent df4f977c2f882228d0fdb186c3ddf17682248f4b reproduced issue 32 in Java diff -r df4f977c2f88 -r 58ea4ef84c92 Resources/Testing/Issue32/Java/README.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Java/README.txt Tue Jan 15 18:46:59 2019 +0100 @@ -0,0 +1,2 @@ +$ sudo apt-get install maven +$ mvn test diff -r df4f977c2f88 -r 58ea4ef84c92 Resources/Testing/Issue32/Java/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Java/pom.xml Tue Jan 15 18:46:59 2019 +0100 @@ -0,0 +1,35 @@ + + + + 4.0.0 + + io.osimis + issue32 + 1.0-SNAPSHOT + + issue32 + + http://www.example.com + + + UTF-8 + 1.8 + 1.8 + + + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + + junit + junit + 4.11 + test + + + diff -r df4f977c2f88 -r 58ea4ef84c92 Resources/Testing/Issue32/Java/src/test/java/io/osimis/AppTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Testing/Issue32/Java/src/test/java/io/osimis/AppTest.java Tue Jan 15 18:46:59 2019 +0100 @@ -0,0 +1,61 @@ +package io.osimis; + +import java.io.IOException; +import org.apache.http.HttpEntity; +import org.apache.http.client.HttpRequestRetryHandler; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.util.EntityUtils; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class AppTest +{ + @Test + public void testKeepAlive() + { + PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); + + CloseableHttpClient client = HttpClients + .custom() + .setConnectionManager(cm) + .setRetryHandler((HttpRequestRetryHandler) (exception, executionCount, context) -> { + System.out.println("ERROR"); + assertTrue(false); + return false; + }).build(); + + HttpRequestBase request = new HttpGet("http://localhost:8042/system"); + + // The following call works + //HttpRequestBase request = new HttpGet("https://api.ipify.org?format=json"); + + for (int i = 0; i < 5; i++) { + System.out.println("================================"); + try (CloseableHttpResponse httpResponse = client.execute(request)) { + String responseContent = null; + + HttpEntity entity = httpResponse.getEntity(); + if (entity != null) { + responseContent = EntityUtils.toString(entity); + } + + System.out.println(httpResponse.getStatusLine().getStatusCode()); + System.out.println(responseContent); + + EntityUtils.consume(entity); + httpResponse.close(); + } catch (IOException e) { + System.out.println("Request error " + e); + } + } + + assertTrue(true); + } +}