From bb91000fb27bac5d642dcabb18ffc85449b5e54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20K=C3=B6rber?= Date: Tue, 13 Mar 2018 22:13:46 +0100 Subject: [PATCH] Wait for the order to become valid --- .../java/org/shredzone/acme4j/ClientTest.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java b/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java index 16d82f69..69e2d501 100644 --- a/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java +++ b/acme4j-example/src/main/java/org/shredzone/acme4j/ClientTest.java @@ -104,8 +104,30 @@ public class ClientTest { csrb.write(out); } - // Get the certificate + // Order the certificate order.execute(csrb.getEncoded()); + + // Wait for the order to complete + try { + int attempts = 10; + while (order.getStatus() != Status.VALID && attempts-- > 0) { + // Did the order fail? + if (order.getStatus() == Status.INVALID) { + throw new AcmeException("Order failed... Giving up."); + } + + // Wait for a few seconds + Thread.sleep(3000L); + + // Then update the status + order.update(); + } + } catch (InterruptedException ex) { + LOG.error("interrupted", ex); + Thread.currentThread().interrupt(); + } + + // Get the certificate Certificate certificate = order.getCertificate(); LOG.info("Success! The certificate for domains " + domains + " has been generated!");