diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java index ccf47a29..e57972ec 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Registration.java @@ -102,17 +102,7 @@ public class Registration extends AcmeResource { } Map json = conn.readJsonResponse(); - unmarshal(json); - - URI location = conn.getLocation(); - if (location != null) { - setLocation(conn.getLocation()); - } - - URI tos = conn.getLink("terms-of-service"); - if (tos != null) { - this.agreement = tos; - } + unmarshal(json, conn); } catch (IOException ex) { throw new AcmeNetworkException(ex); } @@ -269,9 +259,11 @@ public class Registration extends AcmeResource { * * @param json * JSON data + * @param conn + * {@link Connection} with headers to be evaluated */ @SuppressWarnings("unchecked") - private void unmarshal(Map json) { + private void unmarshal(Map json, Connection conn) { if (json.containsKey("agreement")) { try { this.agreement = new URI((String) json.get("agreement")); @@ -290,6 +282,16 @@ public class Registration extends AcmeResource { } } } + + URI location = conn.getLocation(); + if (location != null) { + setLocation(location); + } + + URI tos = conn.getLink("terms-of-service"); + if (tos != null) { + this.agreement = tos; + } } /** @@ -376,18 +378,8 @@ public class Registration extends AcmeResource { conn.throwAcmeException(); } - URI location = conn.getLocation(); - if (location != null) { - setLocation(conn.getLocation()); - } - - URI tos = conn.getLink("terms-of-service"); - if (tos != null) { - Registration.this.agreement = tos; - } - - Registration.this.contacts.clear(); - Registration.this.contacts.addAll(editContacts); + Map json = conn.readJsonResponse(); + unmarshal(json, conn); } catch (IOException ex) { throw new AcmeNetworkException(ex); } diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java index 9e90b5da..d4503af4 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/RegistrationTest.java @@ -308,6 +308,11 @@ public class RegistrationTest { return HttpURLConnection.HTTP_ACCEPTED; } + @Override + public Map readJsonResponse() { + return getJsonAsMap("modifyRegistrationResponse"); + } + @Override public URI getLocation() { return locationUri; diff --git a/acme4j-client/src/test/resources/json.properties b/acme4j-client/src/test/resources/json.properties index b4b760cf..1365b5f3 100644 --- a/acme4j-client/src/test/resources/json.properties +++ b/acme4j-client/src/test/resources/json.properties @@ -21,6 +21,10 @@ modifyRegistration = \ "agreement":"http://example.com/agreement.pdf",\ "contact":["mailto:foo2@example.com"]} +modifyRegistrationResponse = \ + {"agreement":"http://example.com/agreement.pdf",\ + "contact":["mailto:foo2@example.com"]} + recoverRegistration = \ {"resource":"recover-reg",\ "method":"contact",\