本文整理了Java中com.google.api.client.http.HttpRequest.setReadTimeout()
方法的一些代码示例,展示了HttpRequest.setReadTimeout()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.setReadTimeout()
方法的具体详情如下:
包路径:com.google.api.client.http.HttpRequest
类名称:HttpRequest
方法名:setReadTimeout
暂无
代码示例来源:origin: googleapis/google-cloud-java
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
if (delegate != null) {
delegate.initialize(httpRequest);
}
if (connectTimeout >= 0) {
httpRequest.setConnectTimeout(connectTimeout);
}
if (readTimeout >= 0) {
httpRequest.setReadTimeout(readTimeout);
}
HttpHeadersUtils.setHeaders(httpRequest.getHeaders(), headerProvider.getHeaders());
}
};
代码示例来源:origin: GoogleContainerTools/jib
/**
* Sends the request.
*
* @param httpMethod the HTTP request method
* @param request the request to send
* @return the response to the sent request
* @throws IOException if building the HTTP request fails.
*/
public Response send(String httpMethod, Request request) throws IOException {
Preconditions.checkState(httpResponse == null, "Connection can send only one request");
HttpRequest httpRequest =
requestFactory
.buildRequest(httpMethod, url, request.getHttpContent())
.setHeaders(request.getHeaders());
if (request.getHttpTimeout() != null) {
httpRequest.setConnectTimeout(request.getHttpTimeout());
httpRequest.setReadTimeout(request.getHttpTimeout());
}
httpResponse = httpRequest.execute();
return new Response(httpResponse);
}
}
代码示例来源:origin: googleapis/google-cloud-java
private static String getAppEngineProjectIdFromMetadataServer() throws IOException {
String metadata = "http://metadata.google.internal";
String projectIdURL = "/computeMetadata/v1/project/project-id";
GenericUrl url = new GenericUrl(metadata + projectIdURL);
HttpTransport netHttpTransport = new NetHttpTransport();
HttpRequestFactory requestFactory = netHttpTransport.createRequestFactory();
HttpRequest request =
requestFactory
.buildGetRequest(url)
.setConnectTimeout(500)
.setReadTimeout(500)
.setHeaders(new HttpHeaders().set("Metadata-Flavor", "Google"));
HttpResponse response = request.execute();
return headerContainsMetadataFlavor(response) ? response.parseAsString() : null;
}
代码示例来源:origin: spinnaker/kayenta
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
httpRequest.setConnectTimeout(2 * 60000); // 2 minutes connect timeout
httpRequest.setReadTimeout(2 * 60000); // 2 minutes read timeout
}
};
代码示例来源:origin: GoogleCloudPlatform/java-docs-samples
request.setReadTimeout(2 * MILLIS_PER_MINUTE); // 2 minutes read timeout
final HttpUnsuccessfulResponseHandler backoffHandler =
new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()).setSleeper(sleeper);
代码示例来源:origin: stackoverflow.com
Drive drive = new Drive.Builder(this.httpTransport, this.jsonFactory, this.credential).setHttpRequestInitializer(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
credential.initialize(httpRequest);
httpRequest.setConnectTimeout(300 * 60000); // 300 minutes connect timeout
httpRequest.setReadTimeout(300 * 60000); // 300 minutes read timeout
}
}).setApplicationName("My Application").build();
代码示例来源:origin: org.ctoolkit.restapi/ctoolkit-rest-facade-adapter
/**
* Configure HTTP request right before execution.
*
* @param request the HTTP request
* @param numberOfRetries the number of configured retries
* @param readTimeout the request read timeout in milliseconds
*/
protected final void configureHttpRequest( @Nonnull HttpRequest request, int numberOfRetries, int readTimeout )
{
request.setNumberOfRetries( numberOfRetries );
request.setReadTimeout( readTimeout );
}
代码示例来源:origin: stackoverflow.com
new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
credential.initialize(request);
request.setConnectTimeout(CONNECT_TIMEOUT);
request.setReadTimeout(READ_TIMEOUT);
}
}
代码示例来源:origin: stackoverflow.com
new Directory.Builder(
HTTP_TRANSPORT, JSON_FACTORY,new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
credential.initialize(httpRequest);
httpRequest.setConnectTimeout(3); // 3 minutes connect timeout
httpRequest.setReadTimeout(3); // 3 minutes read timeout
System.out.println("Hello"); // Just to track when a http request is made.
}
}).setApplicationName(APPLICATION_NAME).build();
代码示例来源:origin: com.google.enterprise.cloudsearch/google-cloudsearch-connector-sdk
private static HttpRequestInitializer getRequestTimeoutInitializer(
int connectTimeout, int readTimeout) {
return request -> {
request.setConnectTimeout(connectTimeout * 1000);
request.setReadTimeout(readTimeout * 1000);
};
}
代码示例来源:origin: stackoverflow.com
SomeEndpoint.Builder endpointBuilder = new SomeEndpoint.Builder(
AndroidHttp.newCompatibleTransport(),
new JacksonFactory(), new HttpRequestInitializer() {
public void initialize(HttpRequest httpRequest) {
httpRequest.setConnectTimeout(20 * 1000);
httpRequest.setReadTimeout(10 * 1000);
}
});
代码示例来源:origin: stackoverflow.com
BatchRequest batch = service.batch(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
credential.initialize(request);
request.setConnectTimeout(10 * 60000);
request.setReadTimeout(10 * 60000);
System.out.println(request.getReadTimeout() + 2); //Just to track when a batch http request is made.
}
});
代码示例来源:origin: com.netflix.kayenta/kayenta-google
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
httpRequest.setConnectTimeout(2 * 60000); // 2 minutes connect timeout
httpRequest.setReadTimeout(2 * 60000); // 2 minutes read timeout
}
};
代码示例来源:origin: firebase/firebase-admin-java
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
credentialsAdapter.initialize(httpRequest);
httpRequest.setConnectTimeout(connectTimeout);
httpRequest.setReadTimeout(readTimeout);
}
}
代码示例来源:origin: stackoverflow.com
private HttpRequestInitializer setHttpTimeout(final HttpRequestInitializer requestInitializer) {
return new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
httpRequest.setConnectTimeout(3 * 60000); // 3 minutes connect timeout
httpRequest.setReadTimeout(3 * 60000); // 3 minutes read timeout
}
};
}
...
service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, setHttpTimeout(credential)).build();
代码示例来源:origin: spinnaker/halyard
public static HttpRequestInitializer retryRequestInitializer() {
return request -> {
request.setConnectTimeout((int) TimeUnit.MINUTES.toMillis(2));
request.setReadTimeout((int) TimeUnit.MINUTES.toMillis(2));
request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff()));
};
}
代码示例来源:origin: spinnaker/halyard
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()));
};
}
}
代码示例来源:origin: GoogleCloudPlatform/google-cloud-intellij
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
HttpHeaders headers = new HttpHeaders();
httpRequest.setConnectTimeout(timeout);
httpRequest.setReadTimeout(timeout);
httpRequest.setHeaders(headers);
credential.initialize(httpRequest);
}
};
代码示例来源:origin: com.jdroidtools/jdroid-java-googleplay-publisher
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
requestInitializer.initialize(httpRequest);
httpRequest.setConnectTimeout(appContext.getConnectTimeout());
httpRequest.setReadTimeout(appContext.getReadTimeout());
}
};
代码示例来源:origin: marvin-we/steem-java-api-wrapper
@Override
public void initialize(HttpRequest request) throws IOException {
request.setConnectTimeout(SteemJConfig.getInstance().getIdleTimeout());
request.setReadTimeout(SteemJConfig.getInstance().getResponseTimeout());
request.setNumberOfRetries(0);
}
}
内容来源于网络,如有侵权,请联系作者删除!