本文整理匯總了Java中com.google.api.client.http.HttpRequest.setIOExceptionHandler方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.setIOExceptionHandler方法的具體用法?Java HttpRequest.setIOExceptionHandler怎麽用?Java HttpRequest.setIOExceptionHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.setIOExceptionHandler方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
if (connectTimeout != null) {
request.setConnectTimeout((int) connectTimeout.millis());
}
if (readTimeout != null) {
request.setReadTimeout((int) readTimeout.millis());
}
request.setIOExceptionHandler(ioHandler);
request.setInterceptor(credential);
request.setUnsuccessfulResponseHandler((req, resp, supportsRetry) -> {
// Let the credential handle the response. If it failed, we rely on our backoff handler
return credential.handleResponse(req, resp, supportsRetry) || handler.handleResponse(req, resp, supportsRetry);
}
);
}
示例2: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
// Set a timeout for hanging-gets.
// TODO: Do this exclusively for work requests.
request.setReadTimeout(HANGING_GET_TIMEOUT_SEC * 1000);
LoggingHttpBackOffHandler loggingHttpBackOffHandler = new LoggingHttpBackOffHandler(
sleeper,
// Back off on retryable http errors and IOExceptions.
// A back-off multiplier of 2 raises the maximum request retrying time
// to approximately 5 minutes (keeping other back-off parameters to
// their default values).
new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(),
new ExponentialBackOff.Builder().setNanoClock(nanoClock).setMultiplier(2).build(),
ignoredResponseCodes
);
request.setUnsuccessfulResponseHandler(loggingHttpBackOffHandler);
request.setIOExceptionHandler(loggingHttpBackOffHandler);
// Set response initializer
if (responseInterceptor != null) {
request.setResponseInterceptor(responseInterceptor);
}
}
示例3: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
request.setInterceptor(credential);
// Exponential Back-off for 5xx response and 403 rate limit exceeded
// error
HttpBackOffUnsuccessfulResponseHandler backOffHandler = getHttpBackOffUnsuccessfulResponseHandler();
request.setUnsuccessfulResponseHandler(
new CompositeHttpUnsuccessfulResponseHandler(credential, backOffHandler));
// Back-off for socket connection error
request.setIOExceptionHandler(getHttpBackOffIOExceptionHandler());
}
示例4: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest httpRequest) {
final HttpUnsuccessfulResponseHandler backoffHandler =
new HttpBackOffUnsuccessfulResponseHandler(
new ExponentialBackOff.Builder()
.setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
.build())
.setSleeper(sleeper);
httpRequest.setInterceptor(wrappedCredential);
httpRequest.setUnsuccessfulResponseHandler(
new HttpUnsuccessfulResponseHandler() {
int retry = 0;
@Override
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) throws IOException {
if (wrappedCredential.handleResponse(
request, response, supportsRetry)) {
// If credential decides it can handle it,
// the return code or message indicated
// something specific to authentication,
// and no backoff is desired.
return true;
} else if (backoffHandler.handleResponse(
request, response, supportsRetry)) {
// Otherwise, we defer to the judgement of
// our internal backoff handler.
logger.debug("Retrying [{}] times : [{}]", retry, request.getUrl());
return true;
} else {
return false;
}
}
});
httpRequest.setIOExceptionHandler(
new HttpBackOffIOExceptionHandler(
new ExponentialBackOff.Builder()
.setMaxElapsedTimeMillis(((int) maxWait.getMillis()))
.build())
.setSleeper(sleeper)
);
}