本文整理匯總了Java中com.google.api.client.http.HttpRequestInitializer.initialize方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequestInitializer.initialize方法的具體用法?Java HttpRequestInitializer.initialize怎麽用?Java HttpRequestInitializer.initialize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpRequestInitializer
的用法示例。
在下文中一共展示了HttpRequestInitializer.initialize方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setHttpBackoffTimeout
import com.google.api.client.http.HttpRequestInitializer; //導入方法依賴的package包/類
private static HttpRequestInitializer setHttpBackoffTimeout(final HttpRequestInitializer requestInitializer,
final int connectTimeoutMs, final int readTimeoutMs) {
return new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
// Configure exponential backoff on error
// https://developers.google.com/api-client-library/java/google-http-java-client/backoff
ExponentialBackOff backoff = new ExponentialBackOff();
HttpUnsuccessfulResponseHandler backoffHandler = new HttpBackOffUnsuccessfulResponseHandler(backoff)
.setBackOffRequired(HttpBackOffUnsuccessfulResponseHandler.BackOffRequired.ALWAYS);
httpRequest.setUnsuccessfulResponseHandler(backoffHandler);
httpRequest.setConnectTimeout(connectTimeoutMs);
httpRequest.setReadTimeout(readTimeoutMs);
}
};
}
示例2: createHttpTimeout
import com.google.api.client.http.HttpRequestInitializer; //導入方法依賴的package包/類
public final HttpRequestInitializer createHttpTimeout(@NotNull final HttpRequestInitializer requestInitializer, final int value) {
//As seeon on: https://developers.google.com/apps-script/guides/rest/quickstart/java
return httpRequest -> {
requestInitializer.initialize(httpRequest);
// This allows the API to call (and avoid timing out on)
// functions that take up to 6 minutes to complete (the maximum
// allowed script run time), plus a little overhead.
httpRequest.setReadTimeout(value);
};
}
示例3: setHttpTimeout
import com.google.api.client.http.HttpRequestInitializer; //導入方法依賴的package包/類
private static HttpRequestInitializer setHttpTimeout(final HttpRequestInitializer requestInitializer) {
return new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
httpRequest.setConnectTimeout(20 * 60000); // 3 minutes connect timeout
httpRequest.setReadTimeout(20 * 60000); // 3 minutes read timeout
}
};
}
示例4: setHttpTimeout
import com.google.api.client.http.HttpRequestInitializer; //導入方法依賴的package包/類
public static HttpRequestInitializer setHttpTimeout(final HttpRequestInitializer requestInitializer) {
return request -> {
requestInitializer.initialize(request);
request.setConnectTimeout((int) TimeUnit.MINUTES.toMillis(2));
request.setReadTimeout((int) TimeUnit.MINUTES.toMillis(2));
request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
};
}
示例5: setHttpTimeout
import com.google.api.client.http.HttpRequestInitializer; //導入方法依賴的package包/類
/**
* Create a HttpRequestInitializer from the given one, except set
* the HTTP read timeout to be longer than the default (to allow
* called scripts time to execute).
*
* @param {HttpRequestInitializer} requestInitializer the initializer
* to copy and adjust; typically a Credential object.
* @return an initializer with an extended read timeout.
*/
private static HttpRequestInitializer setHttpTimeout(
final HttpRequestInitializer requestInitializer) {
return new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
// This allows the API to call (and avoid timing out on)
// functions that take up to 6 minutes to complete (the maximum
// allowed script run time), plus a little overhead.
httpRequest.setReadTimeout(380000);
}
};
}
示例6: initialize
import com.google.api.client.http.HttpRequestInitializer; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
List<HttpIOExceptionHandler> ioExceptionHandlers = new ArrayList<>();
List<HttpUnsuccessfulResponseHandler> unsuccessfulResponseHandlers = new ArrayList<>();
List<HttpExecuteInterceptor> interceptors = new ArrayList<>();
List<HttpResponseInterceptor> responseInterceptors = new ArrayList<>();
for (HttpRequestInitializer initializer : initializers) {
initializer.initialize(request);
if (request.getIOExceptionHandler() != null) {
ioExceptionHandlers.add(request.getIOExceptionHandler());
request.setIOExceptionHandler(null);
}
if (request.getUnsuccessfulResponseHandler() != null) {
unsuccessfulResponseHandlers.add(request.getUnsuccessfulResponseHandler());
request.setUnsuccessfulResponseHandler(null);
}
if (request.getInterceptor() != null) {
interceptors.add(request.getInterceptor());
request.setInterceptor(null);
}
if (request.getResponseInterceptor() != null) {
responseInterceptors.add(request.getResponseInterceptor());
request.setResponseInterceptor(null);
}
}
request.setIOExceptionHandler(
makeIoExceptionHandler(ioExceptionHandlers));
request.setUnsuccessfulResponseHandler(
makeUnsuccessfulResponseHandler(unsuccessfulResponseHandlers));
request.setInterceptor(
makeInterceptor(interceptors));
request.setResponseInterceptor(
makeResponseInterceptor(responseInterceptors));
}
示例7: setHttpTimeout
import com.google.api.client.http.HttpRequestInitializer; //導入方法依賴的package包/類
/**
* Extend the given HttpRequestInitializer (usually a credentials object)
* with additional initialize() instructions.
*
* @param requestInitializer the initializer to copy and adjust; typically
* a credential object.
* @return an initializer with an extended read timeout.
*/
public static HttpRequestInitializer setHttpTimeout(
final HttpRequestInitializer requestInitializer) {
return new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest)
throws java.io.IOException {
requestInitializer.initialize(httpRequest);
// This allows the API to call (and avoid timing out on)
// functions that take up to 6 minutes to complete (the maximum
// allowed script run time), plus a little overhead.
httpRequest.setReadTimeout(380000);
}
};
}