Use returned Registration object after creation

pull/55/head
Richard Körber 2017-04-19 00:49:07 +02:00
parent b40861c66c
commit 4fe4c12c62
3 changed files with 8 additions and 15 deletions

View File

@ -154,8 +154,7 @@ public class Registration extends AcmeResource {
conn.sendSignedRequest(getLocation(), claims, getSession()); conn.sendSignedRequest(getLocation(), claims, getSession());
conn.accept(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED);
JSON json = conn.readJsonResponse(); unmarshal(conn.readJsonResponse());
unmarshal(json, conn);
} }
} }
@ -343,10 +342,8 @@ public class Registration extends AcmeResource {
* *
* @param json * @param json
* JSON data * JSON data
* @param conn
* {@link Connection} with headers to be evaluated
*/ */
private void unmarshal(JSON json, Connection conn) { protected void unmarshal(JSON json) {
if (json.contains(KEY_TOS_AGREED)) { if (json.contains(KEY_TOS_AGREED)) {
this.termsOfServiceAgreed = json.get(KEY_TOS_AGREED).asBoolean(); this.termsOfServiceAgreed = json.get(KEY_TOS_AGREED).asBoolean();
} }
@ -365,11 +362,6 @@ public class Registration extends AcmeResource {
this.status = Status.parse(json.get(KEY_STATUS).asString()); this.status = Status.parse(json.get(KEY_STATUS).asString());
} }
URL location = conn.getLocation();
if (location != null) {
setLocation(location);
}
loaded = true; loaded = true;
} }
@ -442,7 +434,7 @@ public class Registration extends AcmeResource {
conn.accept(HttpURLConnection.HTTP_ACCEPTED); conn.accept(HttpURLConnection.HTTP_ACCEPTED);
JSON json = conn.readJsonResponse(); JSON json = conn.readJsonResponse();
unmarshal(json, conn); unmarshal(json);
} }
} }
} }

View File

@ -103,11 +103,13 @@ public class RegistrationBuilder {
} }
conn.sendJwkSignedRequest(session.resourceUrl(Resource.NEW_REG), claims, session); conn.sendJwkSignedRequest(session.resourceUrl(Resource.NEW_REG), claims, session);
conn.accept(HttpURLConnection.HTTP_CREATED); conn.accept(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_CREATED);
URL location = conn.getLocation(); URL location = conn.getLocation();
return new Registration(session, location); Registration reg = new Registration(session, location);
reg.unmarshal(conn.readJsonResponse());
return reg;
} }
} }

View File

@ -66,7 +66,7 @@ public class RegistrationBuilderTest {
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED)); assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_CREATED, HttpURLConnection.HTTP_ACCEPTED));
return HttpURLConnection.HTTP_ACCEPTED; return HttpURLConnection.HTTP_ACCEPTED;
} else { } else {
assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_CREATED)); assertThat(httpStatus, isIntArrayContainingInAnyOrder(HttpURLConnection.HTTP_OK, HttpURLConnection.HTTP_CREATED));
return HttpURLConnection.HTTP_CREATED; return HttpURLConnection.HTTP_CREATED;
} }
} }
@ -78,7 +78,6 @@ public class RegistrationBuilderTest {
@Override @Override
public JSON readJsonResponse() { public JSON readJsonResponse() {
assertThat(isUpdate, is(true));
return getJsonAsObject("newRegistrationResponse"); return getJsonAsObject("newRegistrationResponse");
} }
}; };