Remove all uses of HTTP_ACCEPTED

pull/55/head
Richard Körber 2017-05-03 13:39:59 +02:00
parent 4c34f9afb5
commit 300c9dd06c
9 changed files with 37 additions and 58 deletions

View File

@ -141,7 +141,7 @@ public class Authorization extends AcmeResource {
LOG.debug("update"); LOG.debug("update");
try (Connection conn = getSession().provider().connect()) { try (Connection conn = getSession().provider().connect()) {
conn.sendRequest(getLocation(), getSession()); conn.sendRequest(getLocation(), getSession());
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_OK);
unmarshalAuthorization(conn.readJsonResponse()); unmarshalAuthorization(conn.readJsonResponse());
@ -159,7 +159,7 @@ public class Authorization extends AcmeResource {
claims.put("status", "deactivated"); claims.put("status", "deactivated");
conn.sendSignedRequest(getLocation(), claims, getSession()); conn.sendSignedRequest(getLocation(), claims, getSession());
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_OK);
} }
} }

View File

@ -134,7 +134,7 @@ public class Registration extends AcmeResource {
JSONBuilder claims = new JSONBuilder(); JSONBuilder claims = new JSONBuilder();
conn.sendSignedRequest(getLocation(), claims, getSession()); conn.sendSignedRequest(getLocation(), claims, getSession());
conn.accept(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_OK);
unmarshal(conn.readJsonResponse()); unmarshal(conn.readJsonResponse());
} }
@ -399,7 +399,7 @@ public class Registration extends AcmeResource {
} }
conn.sendSignedRequest(getLocation(), claims, getSession()); conn.sendSignedRequest(getLocation(), claims, getSession());
conn.accept(HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_OK);
JSON json = conn.readJsonResponse(); JSON json = conn.readJsonResponse();
unmarshal(json); unmarshal(json);

View File

@ -77,7 +77,7 @@ public class Challenge extends AcmeResource {
LOG.debug("bind"); LOG.debug("bind");
try (Connection conn = session.provider().connect()) { try (Connection conn = session.provider().connect()) {
conn.sendRequest(location, session); conn.sendRequest(location, session);
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_OK);
JSON json = conn.readJsonResponse(); JSON json = conn.readJsonResponse();
if (!(json.contains("type"))) { if (!(json.contains("type"))) {
@ -183,7 +183,7 @@ public class Challenge extends AcmeResource {
respond(claims); respond(claims);
conn.sendSignedRequest(getLocation(), claims, getSession()); conn.sendSignedRequest(getLocation(), claims, getSession());
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_OK);
unmarshall(conn.readJsonResponse()); unmarshall(conn.readJsonResponse());
} }
@ -203,7 +203,7 @@ public class Challenge extends AcmeResource {
LOG.debug("update"); LOG.debug("update");
try (Connection conn = getSession().provider().connect()) { try (Connection conn = getSession().provider().connect()) {
conn.sendRequest(getLocation(), getSession()); conn.sendRequest(getLocation(), getSession());
conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_OK);
unmarshall(conn.readJsonResponse()); unmarshall(conn.readJsonResponse());

View File

@ -297,15 +297,9 @@ public class DefaultConnection implements Connection {
public void handleRetryAfter(String message) throws AcmeException { public void handleRetryAfter(String message) throws AcmeException {
assertConnectionIsOpen(); assertConnectionIsOpen();
try { Optional<Instant> retryAfter = getRetryAfterHeader();
if (conn.getResponseCode() == HttpURLConnection.HTTP_ACCEPTED) { if (retryAfter.isPresent()) {
Optional<Instant> retryAfter = getRetryAfterHeader(); throw new AcmeRetryAfterException(message, retryAfter.get());
if (retryAfter.isPresent()) {
throw new AcmeRetryAfterException(message, retryAfter.get());
}
}
} catch (IOException ex) {
throw new AcmeNetworkException(ex);
} }
} }

View File

@ -97,8 +97,7 @@ public class AuthorizationTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
return HttpURLConnection.HTTP_OK; return HttpURLConnection.HTTP_OK;
} }
@ -151,8 +150,7 @@ public class AuthorizationTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
return HttpURLConnection.HTTP_OK; return HttpURLConnection.HTTP_OK;
} }
@ -204,9 +202,8 @@ public class AuthorizationTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED)); return HttpURLConnection.HTTP_OK;
return HttpURLConnection.HTTP_ACCEPTED;
} }
@Override @Override
@ -263,9 +260,8 @@ public class AuthorizationTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED)); return HttpURLConnection.HTTP_OK;
return HttpURLConnection.HTTP_ACCEPTED;
} }
}; };

View File

@ -67,8 +67,8 @@ public class RegistrationBuilderTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
if (isUpdate) { if (isUpdate) {
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED)); assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
return HttpURLConnection.HTTP_ACCEPTED; return HttpURLConnection.HTTP_OK;
} else { } else {
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_CREATED)); assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_CREATED));
return HttpURLConnection.HTTP_CREATED; return HttpURLConnection.HTTP_CREATED;

View File

@ -72,7 +72,7 @@ public class RegistrationTest {
assertThat(claims.toString(), sameJSONAs(getJSON("updateRegistration").toString())); assertThat(claims.toString(), sameJSONAs(getJSON("updateRegistration").toString()));
assertThat(session, is(notNullValue())); assertThat(session, is(notNullValue()));
jsonResponse = getJSON("updateRegistrationResponse"); jsonResponse = getJSON("updateRegistrationResponse");
response = HttpURLConnection.HTTP_ACCEPTED; response = HttpURLConnection.HTTP_OK;
} }
@Override @Override
@ -153,9 +153,8 @@ public class RegistrationTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED)); return HttpURLConnection.HTTP_OK;
return HttpURLConnection.HTTP_ACCEPTED;
} }
@Override @Override
@ -518,8 +517,8 @@ public class RegistrationTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_ACCEPTED)); assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
return HttpURLConnection.HTTP_ACCEPTED; return HttpURLConnection.HTTP_OK;
} }
@Override @Override

View File

@ -66,9 +66,8 @@ public class ChallengeTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED)); return HttpURLConnection.HTTP_OK;
return HttpURLConnection.HTTP_ACCEPTED;
} }
@Override @Override
@ -156,9 +155,8 @@ public class ChallengeTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED)); return HttpURLConnection.HTTP_OK;
return HttpURLConnection.HTTP_ACCEPTED;
} }
@Override @Override
@ -193,8 +191,7 @@ public class ChallengeTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED));
return HttpURLConnection.HTTP_OK; return HttpURLConnection.HTTP_OK;
} }
@ -237,9 +234,8 @@ public class ChallengeTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED)); return HttpURLConnection.HTTP_OK;
return HttpURLConnection.HTTP_ACCEPTED;
} }
@Override @Override
@ -305,9 +301,8 @@ public class ChallengeTest {
@Override @Override
public int accept(int... httpStatus) throws AcmeException { public int accept(int... httpStatus) throws AcmeException {
assertThat(httpStatus, isIntArrayContainingInAnyOrder( assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK));
HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_ACCEPTED)); return HttpURLConnection.HTTP_OK;
return HttpURLConnection.HTTP_ACCEPTED;
} }
@Override @Override

View File

@ -316,7 +316,7 @@ public class DefaultConnectionTest {
Instant retryDate = Instant.now().plus(Duration.ofHours(10)); Instant retryDate = Instant.now().plus(Duration.ofHours(10));
String retryMsg = "absolute date"; 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.getHeaderField("Retry-After")).thenReturn(retryDate.toString());
when(mockUrlConnection.getHeaderFieldDate("Retry-After", 0L)).thenReturn(retryDate.toEpochMilli()); when(mockUrlConnection.getHeaderFieldDate("Retry-After", 0L)).thenReturn(retryDate.toEpochMilli());
@ -329,7 +329,6 @@ public class DefaultConnectionTest {
assertThat(ex.getMessage(), is(retryMsg)); assertThat(ex.getMessage(), is(retryMsg));
} }
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After"); verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
} }
@ -343,7 +342,7 @@ public class DefaultConnectionTest {
String retryMsg = "relative time"; String retryMsg = "relative time";
when(mockUrlConnection.getResponseCode()) when(mockUrlConnection.getResponseCode())
.thenReturn(HttpURLConnection.HTTP_ACCEPTED); .thenReturn(HttpURLConnection.HTTP_OK);
when(mockUrlConnection.getHeaderField("Retry-After")) when(mockUrlConnection.getHeaderField("Retry-After"))
.thenReturn(String.valueOf(delta)); .thenReturn(String.valueOf(delta));
when(mockUrlConnection.getHeaderFieldDate( when(mockUrlConnection.getHeaderFieldDate(
@ -360,7 +359,6 @@ public class DefaultConnectionTest {
assertThat(ex.getMessage(), is(retryMsg)); assertThat(ex.getMessage(), is(retryMsg));
} }
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After"); verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
} }
@ -370,7 +368,7 @@ public class DefaultConnectionTest {
@Test @Test
public void testHandleRetryAfterHeaderNull() throws AcmeException, IOException { public void testHandleRetryAfterHeaderNull() throws AcmeException, IOException {
when(mockUrlConnection.getResponseCode()) when(mockUrlConnection.getResponseCode())
.thenReturn(HttpURLConnection.HTTP_ACCEPTED); .thenReturn(HttpURLConnection.HTTP_OK);
when(mockUrlConnection.getHeaderField("Retry-After")) when(mockUrlConnection.getHeaderField("Retry-After"))
.thenReturn(null); .thenReturn(null);
@ -381,12 +379,11 @@ public class DefaultConnectionTest {
fail("an AcmeRetryAfterException was thrown"); fail("an AcmeRetryAfterException was thrown");
} }
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After"); 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 @Test
public void testHandleRetryAfterNotAccepted() throws AcmeException, IOException { public void testHandleRetryAfterNotAccepted() throws AcmeException, IOException {
@ -398,8 +395,6 @@ public class DefaultConnectionTest {
} catch (AcmeRetryAfterException ex) { } catch (AcmeRetryAfterException ex) {
fail("an AcmeRetryAfterException was thrown"); fail("an AcmeRetryAfterException was thrown");
} }
verify(mockUrlConnection, atLeastOnce()).getResponseCode();
} }
/** /**
@ -411,7 +406,7 @@ public class DefaultConnectionTest {
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) { try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection; 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)); assertThat(rc, is(HttpURLConnection.HTTP_OK));
} }