Throw AcmeLazyLoadingException on bindChallenge

feature/mock
Richard Körber 2019-10-30 22:32:04 +01:00
parent e7c2bf25f5
commit 8aa7e4ad8e
No known key found for this signature in database
GPG Key ID: AAB9FD19C78AA3E0
3 changed files with 28 additions and 9 deletions

View File

@ -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);
}
}
/**

View File

@ -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<? extends AcmeResource> type, URL location, AcmeException cause) {
super(requireNonNull(type).getSimpleName() + " " + requireNonNull(location), requireNonNull(cause));
this.type = type;
this.location = location;
}
/**

View File

@ -138,7 +138,6 @@ public class LoginTest {
verify(mockProvider).createChallenge(login, data);
}
/**
* Test that binding to a challenge invokes createChallenge
*/