diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java b/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java index cbb850ee..ebcaa296 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/Login.java @@ -25,6 +25,7 @@ import javax.annotation.concurrent.ThreadSafe; import org.shredzone.acme4j.challenge.Challenge; import org.shredzone.acme4j.connector.Connection; import org.shredzone.acme4j.exception.AcmeException; +import org.shredzone.acme4j.exception.AcmeLazyLoadingException; import org.shredzone.acme4j.exception.AcmeProtocolException; import org.shredzone.acme4j.toolbox.JSON; @@ -131,11 +132,16 @@ public class Login { * @param location * Location URL of the order * @return {@link Challenge} bound to the login + * @since 2.8 */ - public Challenge bindChallenge(URL location) throws AcmeException { - Connection connect = session.connect(); - connect.sendSignedPostAsGetRequest(location, this); - return createChallenge(connect.readJsonResponse()); + public Challenge bindChallenge(URL location) { + try { + Connection connect = session.connect(); + connect.sendSignedPostAsGetRequest(location, this); + return createChallenge(connect.readJsonResponse()); + } catch (AcmeException ex) { + throw new AcmeLazyLoadingException(Challenge.class, location, ex); + } } /** diff --git a/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeLazyLoadingException.java b/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeLazyLoadingException.java index 7312e83e..68031c9b 100644 --- a/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeLazyLoadingException.java +++ b/acme4j-client/src/main/java/org/shredzone/acme4j/exception/AcmeLazyLoadingException.java @@ -43,10 +43,24 @@ public class AcmeLazyLoadingException extends RuntimeException { * {@link AcmeException} that was raised */ public AcmeLazyLoadingException(AcmeResource resource, AcmeException cause) { - super(requireNonNull(resource).getClass().getSimpleName() + " " - + requireNonNull(resource).getLocation(), requireNonNull(cause)); - type = resource.getClass(); - location = resource.getLocation(); + this(requireNonNull(resource).getClass(), requireNonNull(resource).getLocation(), cause); + } + + /** + * Creates a new {@link AcmeLazyLoadingException}. + * + * @param type + * {@link AcmeResource} type to be loaded + * @param location + * Resource location + * @param cause + * {@link AcmeException} that was raised + * @since 2.8 + */ + public AcmeLazyLoadingException(Class type, URL location, AcmeException cause) { + super(requireNonNull(type).getSimpleName() + " " + requireNonNull(location), requireNonNull(cause)); + this.type = type; + this.location = location; } /** diff --git a/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java b/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java index 435ca0af..b0d3a3ae 100644 --- a/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java +++ b/acme4j-client/src/test/java/org/shredzone/acme4j/LoginTest.java @@ -138,7 +138,6 @@ public class LoginTest { verify(mockProvider).createChallenge(login, data); } - /** * Test that binding to a challenge invokes createChallenge */