本文整理匯總了Java中com.google.api.client.http.HttpRequest.setReadTimeout方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.setReadTimeout方法的具體用法?Java HttpRequest.setReadTimeout怎麽用?Java HttpRequest.setReadTimeout使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.setReadTimeout方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: sendPostMultipart
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
public static int sendPostMultipart(String urlString, Map<String, String> parameters)
throws IOException {
MultipartContent postBody = new MultipartContent()
.setMediaType(new HttpMediaType("multipart/form-data"));
postBody.setBoundary(MULTIPART_BOUNDARY);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
HttpContent partContent = ByteArrayContent.fromString( // uses UTF-8 internally
null /* part Content-Type */, entry.getValue());
HttpHeaders partHeaders = new HttpHeaders()
.set("Content-Disposition", "form-data; name=\"" + entry.getKey() + "\"");
postBody.addPart(new MultipartContent.Part(partHeaders, partContent));
}
GenericUrl url = new GenericUrl(new URL(urlString));
HttpRequest request = transport.createRequestFactory().buildPostRequest(url, postBody);
request.setHeaders(new HttpHeaders().setUserAgent(CloudToolsInfo.USER_AGENT));
request.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
request.setReadTimeout(DEFAULT_READ_TIMEOUT_MS);
HttpResponse response = request.execute();
return response.getStatusCode();
}
示例3: 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);
}
}
示例4: setHttpTimeout
import com.google.api.client.http.HttpRequest; //導入方法依賴的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
}
};
}
示例5: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
/**
* Initializes this {@link com.google.api.client.auth.oauth2.Credential} subclass. Adds an
* additional interceptor that properly sets the default encoding of the "application/json"
* media type to UTF-8 as required by <a href="http://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>.
*
* @param request The {@link HttpRequest} to be initialized.
*/
@Override
public void initialize(HttpRequest request) throws IOException {
// Initially, pass the initialization on to super.
super.initialize(request);
// Set the timeouts.
request.setConnectTimeout(3 * 600000); // 10 minutes connect timeout
request.setReadTimeout(3 * 600000); // 10 minutes read timeout
// Add an additional interceptor.
request.setResponseInterceptor(new HttpResponseInterceptor() {
@Override
public void interceptResponse(HttpResponse response) throws IOException {
// Decode JSON as UTF-8 if no charset is specified.
if (response.getContentType().equals("application/json") &&
response.getMediaType() != null &&
response.getMediaType().getCharsetParameter() == null)
{
response.getMediaType().setCharsetParameter(StandardCharsets.UTF_8);
}
}
});
// Add a custom handler for unsuccessful responses.
request.setUnsuccessfulResponseHandler(
new UnsuccessfulResponseHandler());
}
示例6: postRequest
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@VisibleForTesting
InputStream postRequest(String url, String boundary, String content) throws IOException {
HttpRequestFactory requestFactory = new NetHttpTransport().createRequestFactory();
HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(url),
ByteArrayContent.fromString("multipart/form-data; boundary=" + boundary, content));
request.setReadTimeout(60000); // 60 seconds is the max App Engine request time
HttpResponse response = request.execute();
if (response.getStatusCode() >= 300) {
throw new IOException("Client Generation failed at server side: " + response.getContent());
} else {
return response.getContent();
}
}
示例7: setHttpTimeout
import com.google.api.client.http.HttpRequest; //導入方法依賴的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);
}
};
}
示例8: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) throws IOException {
request.setConnectTimeout(SteemJImageUploadConfig.getInstance().getConnectTimeout());
request.setReadTimeout(SteemJImageUploadConfig.getInstance().getReadTimeout());
request.setNumberOfRetries(0);
}
示例9: execute
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
/**
* Executes the HTTP request for a temporary or long-lived token.
*
* @throws IOException
*/
public final HttpResponse execute() throws IOException {
ApacheHttpTransport.Builder builder = new ApacheHttpTransport.Builder();
if(this.proxyEnabled) {
builder.setProxy(this.proxy);
}
transport = builder.build();
if(usePost && body != null){
requestBody = ByteArrayContent.fromString(null, body);
}
HttpHeaders headers = new HttpHeaders();
headers.setUserAgent(config.getUserAgent());
headers.setAccept(accept != null ? accept : config.getAccept());
headers.setContentType(contentType == null ? "application/xml" : contentType);
if(ifModifiedSince != null) {
//System.out.println("Set Header " + this.ifModifiedSince);
headers.setIfModifiedSince(this.ifModifiedSince);
}
HttpRequestFactory requestFactory = transport.createRequestFactory();
HttpRequest request;
HttpResponse response = null;
request = requestFactory.buildRequest(this.httpMethod, Url, requestBody);
request.setConnectTimeout(connectTimeout);
request.setReadTimeout(readTimeout);
request.setHeaders(headers);
createParameters().intercept(request);
response = request.execute();
response.setContentLoggingLimit(0);
return response;
}
示例10: start
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void start(Map<String, String> map) {
this.config = new SplunkHttpSinkConnectorConfig(map);
java.util.logging.Logger logger = java.util.logging.Logger.getLogger(HttpTransport.class.getName());
logger.addHandler(new RequestLoggingHandler(log));
if (this.config.curlLoggingEnabled) {
logger.setLevel(Level.ALL);
} else {
logger.setLevel(Level.WARNING);
}
log.info("Starting...");
NetHttpTransport.Builder transportBuilder = new NetHttpTransport.Builder();
if (!this.config.validateCertificates) {
log.warn("Disabling ssl certificate verification.");
try {
transportBuilder.doNotValidateCertificate();
} catch (GeneralSecurityException e) {
throw new IllegalStateException("Exception thrown calling transportBuilder.doNotValidateCertificate()", e);
}
}
if (this.config.hasTrustStorePath) {
log.info("Loading trust store from {}.", this.config.trustStorePath);
try (FileInputStream inputStream = new FileInputStream(this.config.trustStorePath)) {
transportBuilder.trustCertificatesFromJavaKeyStore(inputStream, this.config.trustStorePassword);
} catch (GeneralSecurityException | IOException ex) {
throw new IllegalStateException("Exception thrown while setting up trust certificates.", ex);
}
}
this.transport = transportBuilder.build();
final String authHeaderValue = String.format("Splunk %s", this.config.authToken);
final JsonObjectParser jsonObjectParser = new JsonObjectParser(jsonFactory);
final String userAgent = String.format("kafka-connect-splunk/%s", version());
final boolean curlLogging = this.config.curlLoggingEnabled;
this.httpRequestInitializer = new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest httpRequest) throws IOException {
httpRequest.getHeaders().setAuthorization(authHeaderValue);
httpRequest.getHeaders().setAccept(Json.MEDIA_TYPE);
httpRequest.getHeaders().setUserAgent(userAgent);
httpRequest.setParser(jsonObjectParser);
httpRequest.setEncoding(new GZipEncoding());
httpRequest.setThrowExceptionOnExecuteError(false);
httpRequest.setConnectTimeout(config.connectTimeout);
httpRequest.setReadTimeout(config.readTimeout);
httpRequest.setCurlLoggingEnabled(curlLogging);
// httpRequest.setLoggingEnabled(curlLogging);
}
};
this.httpRequestFactory = this.transport.createRequestFactory(this.httpRequestInitializer);
this.eventCollectorUrl = new GenericUrl();
this.eventCollectorUrl.setRawPath("/services/collector/event");
this.eventCollectorUrl.setPort(this.config.splunkPort);
this.eventCollectorUrl.setHost(this.config.splunkHost);
if (this.config.ssl) {
this.eventCollectorUrl.setScheme("https");
} else {
this.eventCollectorUrl.setScheme("http");
}
log.info("Setting Splunk Http Event Collector Url to {}", this.eventCollectorUrl);
}
示例11: initialize
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@Override
public void initialize(HttpRequest request) {
request.setConnectTimeout(connect_timeout);
request.setReadTimeout(read_timeout);
// With the interceptor will overwrite headers set by the Http client.
request.setInterceptor(rq -> {
HttpHeaders http = rq.getHeaders();
for (Map.Entry<String, String> entry : headers.entrySet()) {
String value = entry.getValue();
switch (entry.getKey().toLowerCase()) {
case "accept":
http.setAccept(value);
break;
case "accept-encoding":
http.setAcceptEncoding(value);
break;
case "authorization":
http.setAuthorization(value);
break;
case "content-encoding":
http.setContentEncoding(value);
break;
case "content-type":
http.setContentType(value);
break;
case "user-agent":
http.setUserAgent(value);
break;
default:
try {
http.set(entry.getKey(), value);
} catch (Exception e) {
// Turn the exception into one that we track and
// print proper error message. This is most likely
// because the header has to be handled with a
// special method.
throw new IOException("Unable to set header " + entry.getKey() + ": " + e.getMessage(), e);
}
break;
}
}
});
}