当前位置: 首页>>代码示例>>Java>>正文


Java AcmeRetryAfterException类代码示例

本文整理汇总了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));
    });
}
 
开发者ID:xkr47,项目名称:vertx-acme4j,代码行数:22,代码来源:AcmeManager.java

示例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");
}
 
开发者ID:shred,项目名称:acme4j,代码行数:24,代码来源:DefaultConnectionTest.java

示例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");
}
 
开发者ID:shred,项目名称:acme4j,代码行数:20,代码来源:DefaultConnectionTest.java

示例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());
    }
}
 
开发者ID:shred,项目名称:acme4j,代码行数:10,代码来源:DefaultConnection.java

示例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");
}
 
开发者ID:shred,项目名称:acme4j,代码行数:30,代码来源:DefaultConnectionTest.java

示例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");
    }
}
 
开发者ID:shred,项目名称:acme4j,代码行数:15,代码来源:DefaultConnectionTest.java

示例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.");
	}
}
 
开发者ID:dernasherbrezon,项目名称:r2cloud,代码行数:51,代码来源:AcmeClient.java


注:本文中的org.shredzone.acme4j.exception.AcmeRetryAfterException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。