本文整理了Java中com.palantir.conjure.java.api.errors.QosException
类的一些代码示例,展示了QosException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QosException
类的具体详情如下:
包路径:com.palantir.conjure.java.api.errors.QosException
类名称:QosException
暂无
代码示例来源:origin: palantir/conjure-java-runtime
@Override
public Response toResponse(QosException qosException) {
log.debug("Possible quality-of-service intervention", qosException);
return qosException.accept(new QosException.Visitor<Response>() {
@Override
public Response visit(QosException.Throttle exception) {
Response.ResponseBuilder response = Response.status(429);
exception.getRetryAfter().ifPresent(duration ->
response.header(HttpHeaders.RETRY_AFTER, Long.toString(duration.get(ChronoUnit.SECONDS))));
return response.build();
}
@Override
public Response visit(QosException.RetryOther exception) {
return Response
.status(308)
.header(HttpHeaders.LOCATION, exception.getRedirectTo().toString())
.build();
}
@Override
public Response visit(QosException.Unavailable exception) {
return Response.status(503).build();
}
});
}
}
代码示例来源:origin: com.palantir.conjure.java.runtime/okhttp-clients
private static QosException handle429(Response response) {
String duration = response.header(HttpHeaders.RETRY_AFTER);
if (duration == null) {
log.debug("Received 429 response, throwing QosException to trigger delayed retry");
return QosException.throttle();
} else {
log.debug("Received 429 response, throwing QosException to trigger delayed retry",
SafeArg.of("duration", duration));
return QosException.throttle(Duration.ofSeconds(Long.parseLong(duration)));
}
}
代码示例来源:origin: com.palantir.conjure.java.runtime/okhttp-clients
private static QosException handle503() {
log.debug("Received 503 response, throwing QosException to trigger failover");
return QosException.unavailable();
}
}
代码示例来源:origin: com.palantir.conjure.java.runtime/okhttp-clients
private Optional<QosException> handle308(Response response) {
String locationHeader = response.header(HttpHeaders.LOCATION);
if (locationHeader == null) {
log.error("Retrieved HTTP status code 308 without Location header, cannot perform "
+ "redirect. This appears to be a server-side protocol violation.");
return Optional.empty();
}
// Note: Do not SafeArg-log the redirectTo URL since it typically contains unsafe information
log.debug("Received 308 response, retrying host at advertised location",
SafeArg.of("location", locationHeader));
try {
return Optional.of(QosException.retryOther(new URL(locationHeader)));
} catch (MalformedURLException e) {
log.error("Failed to parse location header, not performing redirect",
UnsafeArg.of("locationHeader", locationHeader), e);
return Optional.empty();
}
}
代码示例来源:origin: palantir/conjure-java-runtime
private Optional<QosException> handle308(Response response) {
String locationHeader = response.header(HttpHeaders.LOCATION);
if (locationHeader == null) {
log.error("Retrieved HTTP status code 308 without Location header, cannot perform "
+ "redirect. This appears to be a server-side protocol violation.");
return Optional.empty();
}
// Note: Do not SafeArg-log the redirectTo URL since it typically contains unsafe information
log.debug("Received 308 response, retrying host at advertised location",
SafeArg.of("location", locationHeader));
try {
return Optional.of(QosException.retryOther(new URL(locationHeader)));
} catch (MalformedURLException e) {
log.error("Failed to parse location header, not performing redirect",
UnsafeArg.of("locationHeader", locationHeader), e);
return Optional.empty();
}
}
代码示例来源:origin: palantir/conjure-java-runtime
private static QosException handle429(Response response) {
String duration = response.header(HttpHeaders.RETRY_AFTER);
if (duration == null) {
log.debug("Received 429 response, throwing QosException to trigger delayed retry");
return QosException.throttle();
} else {
log.debug("Received 429 response, throwing QosException to trigger delayed retry",
SafeArg.of("duration", duration));
return QosException.throttle(Duration.ofSeconds(Long.parseLong(duration)));
}
}
代码示例来源:origin: palantir/conjure-java-runtime
@Override
public String throwQosRetryFooException() {
try {
throw QosException.retryOther(new URL("http://foo"));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: palantir/conjure-java-runtime
private static QosException handle503() {
log.debug("Received 503 response, throwing QosException to trigger failover");
return QosException.unavailable();
}
}
代码示例来源:origin: com.palantir.conjure.java.runtime/okhttp-clients
qosError.get().accept(createQosVisitor(callback, call));
return;
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testThrottle_withDuration() throws Exception {
QosException exception = QosException.throttle(Duration.ofMinutes(2));
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaders()).containsEntry("Retry-After", ImmutableList.of("120"));
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testRetryOther() throws Exception {
QosException exception = QosException.retryOther(new URL("http://foo"));
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(308);
assertThat(response.getHeaders()).containsEntry("Location", ImmutableList.of("http://foo"));
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testUnavailable() throws Exception {
QosException exception = QosException.unavailable();
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(503);
assertThat(response.getHeaders()).isEmpty();
}
}
代码示例来源:origin: palantir/conjure-java-runtime
qosError.get().accept(createQosVisitor(callback, call));
return;
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testThrottle_withoutDuration() throws Exception {
QosException exception = QosException.throttle();
Response response = mapper.toResponse(exception);
assertThat(response.getStatus()).isEqualTo(429);
assertThat(response.getHeaders()).isEmpty();
}
内容来源于网络,如有侵权,请联系作者删除!