Fix InterruptedException handling in example

pull/30/head
Richard Körber 2016-12-16 00:44:22 +01:00
parent acacaebb52
commit 53712df034
1 changed files with 14 additions and 10 deletions

View File

@ -91,6 +91,7 @@ public class ClientTest {
reg = new RegistrationBuilder().create(session); reg = new RegistrationBuilder().create(session);
LOG.info("Registered a new user, URI: " + reg.getLocation()); LOG.info("Registered a new user, URI: " + reg.getLocation());
} catch (AcmeConflictException ex) { } catch (AcmeConflictException ex) {
LOG.trace("acme4j exception caught", ex);
reg = Registration.bind(session, ex.getLocation()); reg = Registration.bind(session, ex.getLocation());
LOG.info("Account does already exist, URI: " + reg.getLocation()); LOG.info("Account does already exist, URI: " + reg.getLocation());
} }
@ -112,6 +113,7 @@ public class ClientTest {
auth = reg.authorizeDomain(domain); auth = reg.authorizeDomain(domain);
} catch (AcmeUnauthorizedException ex) { } catch (AcmeUnauthorizedException ex) {
// Maybe there are new T&C to accept? // Maybe there are new T&C to accept?
LOG.trace("acme4j exception caught", ex);
boolean accepted = acceptAgreement(reg, agreement); boolean accepted = acceptAgreement(reg, agreement);
if (!accepted) { if (!accepted) {
return; return;
@ -134,19 +136,21 @@ public class ClientTest {
challenge.trigger(); challenge.trigger();
// Poll for the challenge to complete // Poll for the challenge to complete
int attempts = 10; try {
while (challenge.getStatus() != Status.VALID && attempts-- > 0) { int attempts = 10;
if (challenge.getStatus() == Status.INVALID) { while (challenge.getStatus() != Status.VALID && attempts-- > 0) {
LOG.error("Challenge failed... Giving up."); if (challenge.getStatus() == Status.INVALID) {
return; LOG.error("Challenge failed... Giving up.");
} return;
try { }
Thread.sleep(3000L); Thread.sleep(3000L);
} catch (InterruptedException ex) { challenge.update();
LOG.warn("interrupted", ex);
} }
challenge.update(); } catch (InterruptedException ex) {
LOG.error("interrupted", ex);
Thread.currentThread().interrupt();
} }
if (challenge.getStatus() != Status.VALID) { if (challenge.getStatus() != Status.VALID) {
LOG.error("Failed to pass the challenge... Giving up."); LOG.error("Failed to pass the challenge... Giving up.");
return; return;