Skip to content

Commit

Permalink
Fix undesired retry
Browse files Browse the repository at this point in the history
  • Loading branch information
malkusch committed Nov 7, 2023
1 parent dc6ad0a commit 49b920a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/main/java/de/malkusch/km200/http/UrlHttp.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/de/malkusch/km200/KM200Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")));
}

Expand Down

0 comments on commit 49b920a

Please sign in to comment.