mirror of https://github.com/shred/acme4j
Remove all uses of HTTP_ACCEPTED
parent
4c34f9afb5
commit
300c9dd06c
|
@ -141,7 +141,7 @@ public class Authorization extends AcmeResource {
|
|||
LOG.debug("update");
|
||||
try (Connection conn = getSession().provider().connect()) {
|
||||
conn.sendRequest(getLocation(), getSession());
|
||||
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED);
|
||||
conn.accept(HttpURLConnection.HTTP_OK);
|
||||
|
||||
unmarshalAuthorization(conn.readJsonResponse());
|
||||
|
||||
|
@ -159,7 +159,7 @@ public class Authorization extends AcmeResource {
|
|||
claims.put("status", "deactivated");
|
||||
|
||||
conn.sendSignedRequest(getLocation(), claims, getSession());
|
||||
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED);
|
||||
conn.accept(HttpURLConnection.HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -134,7 +134,7 @@ public class Registration extends AcmeResource {
|
|||
JSONBuilder claims = new JSONBuilder();
|
||||
|
||||
conn.sendSignedRequest(getLocation(), claims, getSession());
|
||||
conn.accept(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED);
|
||||
conn.accept(HttpURLConnection.HTTP_OK);
|
||||
|
||||
unmarshal(conn.readJsonResponse());
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ public class Registration extends AcmeResource {
|
|||
}
|
||||
|
||||
conn.sendSignedRequest(getLocation(), claims, getSession());
|
||||
conn.accept(HttpURLConnection.HTTP_ACCEPTED);
|
||||
conn.accept(HttpURLConnection.HTTP_OK);
|
||||
|
||||
JSON json = conn.readJsonResponse();
|
||||
unmarshal(json);
|
||||
|
|
|
@ -77,7 +77,7 @@ public class Challenge extends AcmeResource {
|
|||
LOG.debug("bind");
|
||||
try (Connection conn = session.provider().connect()) {
|
||||
conn.sendRequest(location, session);
|
||||
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED);
|
||||
conn.accept(HttpURLConnection.HTTP_OK);
|
||||
|
||||
JSON json = conn.readJsonResponse();
|
||||
if (!(json.contains("type"))) {
|
||||
|
@ -183,7 +183,7 @@ public class Challenge extends AcmeResource {
|
|||
respond(claims);
|
||||
|
||||
conn.sendSignedRequest(getLocation(), claims, getSession());
|
||||
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED);
|
||||
conn.accept(HttpURLConnection.HTTP_OK);
|
||||
|
||||
unmarshall(conn.readJsonResponse());
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ public class Challenge extends AcmeResource {
|
|||
LOG.debug("update");
|
||||
try (Connection conn = getSession().provider().connect()) {
|
||||
conn.sendRequest(getLocation(), getSession());
|
||||
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED);
|
||||
conn.accept(HttpURLConnection.HTTP_OK);
|
||||
|
||||
unmarshall(conn.readJsonResponse());
|
||||
|
||||
|
|
|
@ -297,15 +297,9 @@ public class DefaultConnection implements Connection {
|
|||
public void handleRetryAfter(String message) throws AcmeException {
|
||||
assertConnectionIsOpen();
|
||||
|
||||
try {
|
||||
if (conn.getResponseCode() == HttpURLConnection.HTTP_ACCEPTED) {
|
||||
Optional<Instant> retryAfter = getRetryAfterHeader();
|
||||
if (retryAfter.isPresent()) {
|
||||
throw new AcmeRetryAfterException(message, retryAfter.get());
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new AcmeNetworkException(ex);
|
||||
Optional<Instant> retryAfter = getRetryAfterHeader();
|
||||
if (retryAfter.isPresent()) {
|
||||
throw new AcmeRetryAfterException(message, retryAfter.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -97,8 +97,7 @@ public class AuthorizationTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
|
@ -151,8 +150,7 @@ public class AuthorizationTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
|
@ -204,9 +202,8 @@ public class AuthorizationTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -263,9 +260,8 @@ public class AuthorizationTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -67,8 +67,8 @@ public class RegistrationBuilderTest {
|
|||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
if (isUpdate) {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
} else {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_CREATED));
|
||||
return HttpURLConnection.HTTP_CREATED;
|
||||
|
|
|
@ -72,7 +72,7 @@ public class RegistrationTest {
|
|||
assertThat(claims.toString(), sameJSONAs(getJSON("updateRegistration").toString()));
|
||||
assertThat(session, is(notNullValue()));
|
||||
jsonResponse = getJSON("updateRegistrationResponse");
|
||||
response = HttpURLConnection.HTTP_ACCEPTED;
|
||||
response = HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -153,9 +153,8 @@ public class RegistrationTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -518,8 +517,8 @@ public class RegistrationTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -66,9 +66,8 @@ public class ChallengeTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,9 +155,8 @@ public class ChallengeTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -193,8 +191,7 @@ public class ChallengeTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
|
@ -237,9 +234,8 @@ public class ChallengeTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -305,9 +301,8 @@ public class ChallengeTest {
|
|||
|
||||
@Override
|
||||
public int accept(int... httpStatus) throws AcmeException {
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(
|
||||
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
|
||||
return HttpURLConnection.HTTP_ACCEPTED;
|
||||
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
|
||||
return HttpURLConnection.HTTP_OK;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -316,7 +316,7 @@ public class DefaultConnectionTest {
|
|||
Instant retryDate = Instant.now().plus(Duration.ofHours(10));
|
||||
String retryMsg = "absolute date";
|
||||
|
||||
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_ACCEPTED);
|
||||
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
|
||||
when(mockUrlConnection.getHeaderField("Retry-After")).thenReturn(retryDate.toString());
|
||||
when(mockUrlConnection.getHeaderFieldDate("Retry-After", 0L)).thenReturn(retryDate.toEpochMilli());
|
||||
|
||||
|
@ -329,7 +329,6 @@ public class DefaultConnectionTest {
|
|||
assertThat(ex.getMessage(), is(retryMsg));
|
||||
}
|
||||
|
||||
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
|
||||
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
|
||||
}
|
||||
|
||||
|
@ -343,7 +342,7 @@ public class DefaultConnectionTest {
|
|||
String retryMsg = "relative time";
|
||||
|
||||
when(mockUrlConnection.getResponseCode())
|
||||
.thenReturn(HttpURLConnection.HTTP_ACCEPTED);
|
||||
.thenReturn(HttpURLConnection.HTTP_OK);
|
||||
when(mockUrlConnection.getHeaderField("Retry-After"))
|
||||
.thenReturn(String.valueOf(delta));
|
||||
when(mockUrlConnection.getHeaderFieldDate(
|
||||
|
@ -360,7 +359,6 @@ public class DefaultConnectionTest {
|
|||
assertThat(ex.getMessage(), is(retryMsg));
|
||||
}
|
||||
|
||||
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
|
||||
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
|
||||
}
|
||||
|
||||
|
@ -370,7 +368,7 @@ public class DefaultConnectionTest {
|
|||
@Test
|
||||
public void testHandleRetryAfterHeaderNull() throws AcmeException, IOException {
|
||||
when(mockUrlConnection.getResponseCode())
|
||||
.thenReturn(HttpURLConnection.HTTP_ACCEPTED);
|
||||
.thenReturn(HttpURLConnection.HTTP_OK);
|
||||
when(mockUrlConnection.getHeaderField("Retry-After"))
|
||||
.thenReturn(null);
|
||||
|
||||
|
@ -381,12 +379,11 @@ public class DefaultConnectionTest {
|
|||
fail("an AcmeRetryAfterException was thrown");
|
||||
}
|
||||
|
||||
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
|
||||
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if no HTTP_ACCEPTED status is correctly handled.
|
||||
* Test if missing retry-after header is correctly handled.
|
||||
*/
|
||||
@Test
|
||||
public void testHandleRetryAfterNotAccepted() throws AcmeException, IOException {
|
||||
|
@ -398,8 +395,6 @@ public class DefaultConnectionTest {
|
|||
} catch (AcmeRetryAfterException ex) {
|
||||
fail("an AcmeRetryAfterException was thrown");
|
||||
}
|
||||
|
||||
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -411,7 +406,7 @@ public class DefaultConnectionTest {
|
|||
|
||||
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
|
||||
conn.conn = mockUrlConnection;
|
||||
int rc = conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED);
|
||||
int rc = conn.accept(HttpURLConnection.HTTP_OK);
|
||||
assertThat(rc, is(HttpURLConnection.HTTP_OK));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue