本文整理汇总了Java中org.shredzone.acme4j.exception.AcmeRetryAfterException类的典型用法代码示例。如果您正苦于以下问题:Java AcmeRetryAfterException类的具体用法?Java AcmeRetryAfterException怎么用?Java AcmeRetryAfterException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AcmeRetryAfterException类属于org.shredzone.acme4j.exception包,在下文中一共展示了AcmeRetryAfterException类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fetchWithRetry
import org.shredzone.acme4j.exception.AcmeRetryAfterException; //导入依赖的package包/类
<T> void fetchWithRetry(Logger logger, Callable<T> blockingHandler, Future<T> done) {
vertx.executeBlocking((Future<T> fut) -> {
try {
fut.complete(blockingHandler.call());
} catch (Exception e) {
fut.fail(e);
}
}, ar -> {
if (ar.failed() && !(ar.cause() instanceof AcmeRetryAfterException)) {
done.fail(ar.cause());
return;
}
if (ar.succeeded() && ar.result() != null) {
done.complete(ar.result());
return;
}
long nextSleep = ar.succeeded() ? 3000 : ((AcmeRetryAfterException) ar.cause()).getRetryAfter().getTime() - currentTimeMillis();
logger.info("Recheck in {}ms @ {}", nextSleep, new Date(System.currentTimeMillis() + nextSleep));
vertx.setTimer(nextSleep, timerId -> fetchWithRetry(logger, blockingHandler, done));
});
}
示例2: testHandleRetryAfterHeaderDate
import org.shredzone.acme4j.exception.AcmeRetryAfterException; //导入依赖的package包/类
/**
* Test if Retry-After header with absolute date is correctly parsed.
*/
@Test
public void testHandleRetryAfterHeaderDate() throws AcmeException, IOException {
Instant retryDate = Instant.now().plus(Duration.ofHours(10)).truncatedTo(ChronoUnit.MILLIS);
String retryMsg = "absolute date";
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
when(mockUrlConnection.getHeaderField("Retry-After")).thenReturn(retryDate.toString());
when(mockUrlConnection.getHeaderFieldDate("Retry-After", 0L)).thenReturn(retryDate.toEpochMilli());
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection;
conn.handleRetryAfter(retryMsg);
fail("no AcmeRetryAfterException was thrown");
} catch (AcmeRetryAfterException ex) {
assertThat(ex.getRetryAfter(), is(retryDate));
assertThat(ex.getMessage(), is(retryMsg));
}
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
}
示例3: testHandleRetryAfterHeaderNull
import org.shredzone.acme4j.exception.AcmeRetryAfterException; //导入依赖的package包/类
/**
* Test if no Retry-After header is correctly handled.
*/
@Test
public void testHandleRetryAfterHeaderNull() throws AcmeException, IOException {
when(mockUrlConnection.getResponseCode())
.thenReturn(HttpURLConnection.HTTP_OK);
when(mockUrlConnection.getHeaderField("Retry-After"))
.thenReturn(null);
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection;
conn.handleRetryAfter("no header");
} catch (AcmeRetryAfterException ex) {
fail("an AcmeRetryAfterException was thrown");
}
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
}
示例4: handleRetryAfter
import org.shredzone.acme4j.exception.AcmeRetryAfterException; //导入依赖的package包/类
@Override
public void handleRetryAfter(String message) throws AcmeException {
assertConnectionIsOpen();
Optional<Instant> retryAfter = getRetryAfterHeader();
if (retryAfter.isPresent()) {
throw new AcmeRetryAfterException(message, retryAfter.get());
}
}
示例5: testHandleRetryAfterHeaderDelta
import org.shredzone.acme4j.exception.AcmeRetryAfterException; //导入依赖的package包/类
/**
* Test if Retry-After header with relative timespan is correctly parsed.
*/
@Test
public void testHandleRetryAfterHeaderDelta() throws AcmeException, IOException {
int delta = 10 * 60 * 60;
long now = System.currentTimeMillis();
String retryMsg = "relative time";
when(mockUrlConnection.getResponseCode())
.thenReturn(HttpURLConnection.HTTP_OK);
when(mockUrlConnection.getHeaderField("Retry-After"))
.thenReturn(String.valueOf(delta));
when(mockUrlConnection.getHeaderFieldDate(
ArgumentMatchers.eq("Date"),
ArgumentMatchers.anyLong()))
.thenReturn(now);
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection;
conn.handleRetryAfter(retryMsg);
fail("no AcmeRetryAfterException was thrown");
} catch (AcmeRetryAfterException ex) {
assertThat(ex.getRetryAfter(), is(Instant.ofEpochMilli(now).plusSeconds(delta)));
assertThat(ex.getMessage(), is(retryMsg));
}
verify(mockUrlConnection, atLeastOnce()).getHeaderField("Retry-After");
}
示例6: testHandleRetryAfterNotAccepted
import org.shredzone.acme4j.exception.AcmeRetryAfterException; //导入依赖的package包/类
/**
* Test if missing retry-after header is correctly handled.
*/
@Test
public void testHandleRetryAfterNotAccepted() throws AcmeException, IOException {
when(mockUrlConnection.getResponseCode()).thenReturn(HttpURLConnection.HTTP_OK);
try (DefaultConnection conn = new DefaultConnection(mockHttpConnection)) {
conn.conn = mockUrlConnection;
conn.handleRetryAfter("http ok");
} catch (AcmeRetryAfterException ex) {
fail("an AcmeRetryAfterException was thrown");
}
}
示例7: authorize
import org.shredzone.acme4j.exception.AcmeRetryAfterException; //导入依赖的package包/类
private void authorize(Registration reg, String domain) throws AcmeException, FileNotFoundException, IOException {
messages.add("authorizing domain: " + domain, LOG);
Authorization auth = reg.authorizeDomain(domain);
messages.add("find http challenge", LOG);
Http01Challenge challenge1 = auth.findChallenge(Http01Challenge.TYPE);
if (challenge1 == null) {
throw new AcmeException("Found no " + Http01Challenge.TYPE + " challenge, don't know what to do...");
}
messages.add("saving challenge request", LOG);
try (FileOutputStream fos = new FileOutputStream(new File(challengePath, challenge1.getToken()))) {
fos.write(challenge1.getAuthorization().getBytes(StandardCharsets.UTF_8));
}
Challenge challenge = challenge1;
if (challenge.getStatus() == Status.VALID) {
messages.add("challenge already successeded", LOG);
return;
}
messages.add("trigger challenge", LOG);
challenge.trigger();
// Poll for the challenge to complete.
try {
long retryTimeout = INITIAL_RETRY;
while (challenge.getStatus() != Status.VALID) {
// Did the authorization fail?
if (challenge.getStatus() == Status.INVALID) {
messages.add("Authorization failed: " + challenge.getError().getDetail());
throw new AcmeException("Challenge failed...");
}
Thread.sleep(retryTimeout);
try {
messages.add("update challenge", LOG);
challenge.update();
} catch (AcmeRetryAfterException e) {
retryTimeout = e.getRetryAfter().toEpochMilli() - System.currentTimeMillis();
messages.add("not ready. retry after: " + retryTimeout + " millis", LOG);
}
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
// All reattempts are used up and there is still no valid authorization?
if (challenge.getStatus() != Status.VALID) {
throw new AcmeException("Failed to pass the challenge for domain " + domain + ", ... Giving up.");
}
}