diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java index 740fa77e..aa67baf2 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/challenge/Challenge.java @@ -13,12 +13,8 @@ */ package org.shredzone.acme4j.challenge; -import static java.util.stream.Collectors.toList; - import java.net.URL; import java.time.Instant; -import java.util.Collections; -import java.util.List; import java.util.Objects; import org.shredzone.acme4j.AcmeJsonResource; @@ -29,7 +25,6 @@ import org.shredzone.acme4j.connector.Connection; import org.shredzone.acme4j.exception.AcmeException; import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.toolbox.JSON; -import org.shredzone.acme4j.toolbox.JSON.Array; import org.shredzone.acme4j.toolbox.JSONBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,7 +46,7 @@ public class Challenge extends AcmeJsonResource { protected static final String KEY_URL = "url"; protected static final String KEY_STATUS = "status"; protected static final String KEY_VALIDATED = "validated"; - protected static final String KEY_ERRORS = "errors"; + protected static final String KEY_ERROR = "error"; /** * Creates a new generic {@link Challenge} object. @@ -114,29 +109,12 @@ public class Challenge extends AcmeJsonResource { } /** - * Returns a list of reasons why the challenge has failed in the past, if returned by - * the server. New errors are always appended to the end of the list. + * Returns a reason why the challenge has failed in the past, if returned by the + * server. If there are multiple errors, they can be found in + * {@link Problem#getSubProblems()}. */ - public List getErrors() { - URL location = getLocation(); - return Collections.unmodifiableList(getJSON().get(KEY_ERRORS) - .asArray() - .stream() - .map(it -> it.asProblem(location)) - .collect(toList())); - } - - /** - * Returns the last reason why the challenge has failed, if returned by the server. - * {@code null} if there are no errors. - */ - public Problem getLastError() { - Array errors = getJSON().get(KEY_ERRORS).asArray(); - if (!errors.isEmpty()) { - return errors.get(errors.size() - 1).asProblem(getLocation()); - } else { - return null; - } + public Problem getError() { + return getJSON().get(KEY_ERROR).asProblem(getLocation()); } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java index a9acca4c..5911844d 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/challenge/ChallengeTest.java @@ -26,7 +26,6 @@ import java.net.URISyntaxException; import java.net.URL; import java.time.Duration; import java.time.Instant; -import java.util.List; import org.jose4j.lang.JoseException; import org.junit.Before; @@ -102,21 +101,11 @@ public class ChallengeTest { assertThat(challenge.getJSON().get("notPresent").asString(), is(nullValue())); assertThat(challenge.getJSON().get("notPresentUrl").asURL(), is(nullValue())); - List errors = challenge.getErrors(); - assertThat(errors, is(notNullValue())); - assertThat(errors, hasSize(2)); - assertThat(errors.get(0).getType(), is(URI.create("urn:ietf:params:acme:error:connection"))); - assertThat(errors.get(0).getDetail(), is("connection refused")); - assertThat(errors.get(0).getInstance(), is(URI.create("http://example.com/documents/error.html"))); - assertThat(errors.get(1).getType(), is(URI.create("urn:ietf:params:acme:error:incorrectResponse"))); - assertThat(errors.get(1).getDetail(), is("bad token")); - assertThat(errors.get(1).getInstance(), is(URI.create("http://example.com/documents/faq.html"))); - - Problem lastError = challenge.getLastError(); - assertThat(lastError, is(notNullValue())); - assertThat(lastError.getType(), is(URI.create("urn:ietf:params:acme:error:incorrectResponse"))); - assertThat(lastError.getDetail(), is("bad token")); - assertThat(lastError.getInstance(), is(URI.create("http://example.com/documents/faq.html"))); + Problem error = challenge.getError(); + assertThat(error, is(notNullValue())); + assertThat(error.getType(), is(URI.create("urn:ietf:params:acme:error:incorrectResponse"))); + assertThat(error.getDetail(), is("bad token")); + assertThat(error.getInstance(), is(URI.create("http://example.com/documents/faq.html"))); } /** diff --git a/acme4j-client/src/test/resources/json/genericChallenge.json b/acme4j-client/src/test/resources/json/genericChallenge.json index 055143b4..2b3a4a12 100644 --- a/acme4j-client/src/test/resources/json/genericChallenge.json +++ b/acme4j-client/src/test/resources/json/genericChallenge.json @@ -3,16 +3,9 @@ "status": "invalid", "url": "http://example.com/challenge/123", "validated": "2015-12-12T17:19:36.336785823Z", - "errors": [ - { - "type": "urn:ietf:params:acme:error:connection", - "detail": "connection refused", - "instance": "/documents/error.html" - }, - { - "type": "urn:ietf:params:acme:error:incorrectResponse", - "detail": "bad token", - "instance": "/documents/faq.html" - } - ] + "error": { + "type": "urn:ietf:params:acme:error:incorrectResponse", + "detail": "bad token", + "instance": "/documents/faq.html" + } }