diff options
author | Thomas <> | 2024-04-03 18:40:59 +0200 |
---|---|---|
committer | Thomas <> | 2024-04-03 18:40:59 +0200 |
commit | ff340b3aec5193b066b3cf6ee6cbc9c542de48df (patch) | |
tree | 00186bd13aa86f6016383aa96837f1a2de76a239 /eaaf_core_utils/src/test | |
parent | 487011328411309e0be774d5e9371346a788d9ba (diff) | |
download | EAAF-Components-ff340b3aec5193b066b3cf6ee6cbc9c542de48df.tar.gz EAAF-Components-ff340b3aec5193b066b3cf6ee6cbc9c542de48df.tar.bz2 EAAF-Components-ff340b3aec5193b066b3cf6ee6cbc9c542de48df.zip |
fix(http): include retry on HTTP POST requests
Reason: that feature looks be removed during refactoring from Apache HTTP Client v4.x to 5.x
Diffstat (limited to 'eaaf_core_utils/src/test')
-rw-r--r-- | eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java | 94 |
1 files changed, 62 insertions, 32 deletions
diff --git a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java index 243205c9..c566380e 100644 --- a/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java +++ b/eaaf_core_utils/src/test/java/at/gv/egiz/eaaf/core/test/http/HttpClientFactoryTest.java @@ -394,38 +394,6 @@ public class HttpClientFactoryTest { } @Test - public void httpPostRetryNotAllowed() throws EaafException, InterruptedException, - ClientProtocolException, IOException { - final HttpClientConfiguration config = - new HttpClientConfiguration("jUnit_retry_" + RandomStringUtils.randomAlphabetic(3)); - config.setHttpErrorRetryCount(2); - - final CloseableHttpClient client = httpClientFactory.getHttpClient(config); - Assert.assertNotNull("No httpClient", client); - - - mockWebServer = new MockWebServer(); - mockServerUrl = mockWebServer.url("/sp/junit"); - mockWebServer.enqueue(new MockResponse() - .setSocketPolicy(SocketPolicy.NO_RESPONSE) - .setResponseCode(HttpURLConnection.HTTP_NO_CONTENT)); - mockWebServer.enqueue(new MockResponse().setResponseCode(200) - .setBody("GetData")); - - //request webservice - final HttpUriRequest httpGet1 = new HttpPost(mockServerUrl.url().toString()); - try { - client.execute(httpGet1); - Assert.fail("HTTP POST retry not allowed"); - - } catch (final SocketTimeoutException e) { - Assert.assertNotNull("No errorMsg", e.getMessage()); - - } - - } - - @Test public void testHttpClientRetryOneTime() throws EaafException, InterruptedException, ClientProtocolException, IOException { final HttpClientConfiguration config = @@ -552,6 +520,68 @@ public class HttpClientFactoryTest { } @Test + public void testHttpClientRetryOneTimePost() throws EaafException, InterruptedException, + ClientProtocolException, IOException { + final HttpClientConfiguration config = + new HttpClientConfiguration("jUnit_retry_" + RandomStringUtils.randomAlphabetic(3)); + config.setHttpErrorRetryCount(2); + config.setHttpPostRetryAllowed(true); + + final CloseableHttpClient client = httpClientFactory.getHttpClient(config); + Assert.assertNotNull("No httpClient", client); + + mockWebServer = new MockWebServer(); + mockServerUrl = mockWebServer.url("/sp/junit"); + mockWebServer.enqueue(new MockResponse() + .setSocketPolicy(SocketPolicy.NO_RESPONSE) + .setResponseCode(HttpURLConnection.HTTP_NO_CONTENT)); + + String bodyData = RandomStringUtils.randomAlphanumeric(10); + mockWebServer.enqueue(new MockResponse().setResponseCode(200) + .setBody(bodyData)); + + // request webservice + final HttpUriRequest httpGet1 = new HttpPost(mockServerUrl.url().toString()); + final Triple<StatusLine, ByteArrayInputStream, ContentType> httpResp1 = client.execute(httpGet1, + HttpUtils.bodyStatusCodeResponseHandler()); + Assert.assertEquals("http statusCode", 200, httpResp1.getFirst().getStatusCode()); + Assert.assertEquals("http statusCode", bodyData, new String(StreamUtils.readStream(httpResp1 + .getSecond()))); + + } + + @Test + public void httpPostRetryNotAllowed() throws EaafException, InterruptedException, + ClientProtocolException, IOException { + final HttpClientConfiguration config = + new HttpClientConfiguration("jUnit_retry_" + RandomStringUtils.randomAlphabetic(3)); + config.setHttpErrorRetryCount(2); + config.setHttpPostRetryAllowed(false); + + final CloseableHttpClient client = httpClientFactory.getHttpClient(config); + Assert.assertNotNull("No httpClient", client); + + mockWebServer = new MockWebServer(); + mockServerUrl = mockWebServer.url("/sp/junit"); + mockWebServer.enqueue(new MockResponse() + .setSocketPolicy(SocketPolicy.NO_RESPONSE) + .setResponseCode(HttpURLConnection.HTTP_NO_CONTENT)); + mockWebServer.enqueue(new MockResponse().setResponseCode(200) + .setBody("GetData")); + + // request webservices + final HttpUriRequest httpGet1 = new HttpPost(mockServerUrl.url().toString()); + try { + client.execute(httpGet1); + Assert.fail("HTTP POST retry not allowed"); + + } catch (final SocketTimeoutException e) { + Assert.assertNotNull("No errorMsg", e.getMessage()); + + } + } + + @Test public void getCustomClientBasicAuthNoPassword() throws EaafException { final HttpClientConfiguration config = new HttpClientConfiguration("jUnit"); config.setAuthMode("password"); |