diff --git a/src/main/java/de/malkusch/km200/http/UrlHttp.java b/src/main/java/de/malkusch/km200/http/UrlHttp.java index d6fc9b8..d6a0ff2 100644 --- a/src/main/java/de/malkusch/km200/http/UrlHttp.java +++ b/src/main/java/de/malkusch/km200/http/UrlHttp.java @@ -4,6 +4,7 @@ import java.net.HttpURLConnection; import java.net.SocketTimeoutException; import java.net.URL; +import java.net.http.HttpClient; import java.net.http.HttpTimeoutException; import java.time.Duration; @@ -16,6 +17,15 @@ public final class UrlHttp extends Http { private final String userAgent; private final int timeoutMillis; + /** + * Avoid undesired POST retries from UrlConnection + * + * {@link HttpClient} + */ + static { + System.setProperty("sun.net.http.retryPost", "false"); + } + public UrlHttp(String uri, String userAgent, Duration timeout) { this.uri = uri; this.userAgent = userAgent; diff --git a/src/test/java/de/malkusch/km200/KM200Test.java b/src/test/java/de/malkusch/km200/KM200Test.java index 3ae04ed..f2568e7 100644 --- a/src/test/java/de/malkusch/km200/KM200Test.java +++ b/src/test/java/de/malkusch/km200/KM200Test.java @@ -5,7 +5,6 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.lessThanOrExactly; import static com.github.tomakehurst.wiremock.client.WireMock.notFound; import static com.github.tomakehurst.wiremock.client.WireMock.ok; import static com.github.tomakehurst.wiremock.client.WireMock.post; @@ -404,7 +403,6 @@ public void updateShouldNotRetryOnBadResponse(Fault fault) throws Exception { var km200 = new KM200(URI, TIMEOUT, GATEWAY_PASSWORD, PRIVATE_PASSWORD, SALT); assertThrows(IOException.class, () -> km200.update("/update-bad-response-retry", 42)); - // verify(lessThanOrExactly(2), postRequestedFor(urlEqualTo("/update-bad-response-retry"))); verify(1, postRequestedFor(urlEqualTo("/update-bad-response-retry"))); }