本文整理匯總了Java中com.google.api.client.http.HttpRequest.setThrowExceptionOnExecuteError方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.setThrowExceptionOnExecuteError方法的具體用法?Java HttpRequest.setThrowExceptionOnExecuteError怎麽用?Java HttpRequest.setThrowExceptionOnExecuteError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.setThrowExceptionOnExecuteError方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: ServiceConfigSupplier
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
@VisibleForTesting
ServiceConfigSupplier(
Environment environment,
HttpTransport httpTransport,
JsonFactory jsonFactory,
final GoogleCredential credential) {
this.environment = environment;
HttpRequestInitializer requestInitializer = new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
request.setThrowExceptionOnExecuteError(false);
credential.initialize(request);
}
};
this.serviceManagement =
new ServiceManagement.Builder(httpTransport, jsonFactory, requestInitializer)
.setApplicationName("Endpoints Frameworks Java")
.build();
}
示例2: createHttpResponse
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
public static HttpResponse createHttpResponse(int statusCode, InputStream content)
throws IOException {
FakeHttpTransport transport = new FakeHttpTransport(statusCode, content);
HttpRequestFactory factory = transport.createRequestFactory();
HttpRequest request =
factory.buildRequest(
"foo", new GenericUrl("http://example.com/bar"), new EmptyHttpContent());
request.setThrowExceptionOnExecuteError(false);
return request.execute();
}
開發者ID:google,項目名稱:java-monitoring-client-library,代碼行數:11,代碼來源:GoogleJsonResponseExceptionHelper.java
示例3: googleJsonResponseException
import com.google.api.client.http.HttpRequest; //導入方法依賴的package包/類
/**
* Builds a fake GoogleJsonResponseException for testing API error handling.
*/
private static GoogleJsonResponseException googleJsonResponseException(
final int status, final String reason, final String message) throws IOException {
final JsonFactory jsonFactory = new JacksonFactory();
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
ErrorInfo errorInfo = new ErrorInfo();
errorInfo.setReason(reason);
errorInfo.setMessage(message);
errorInfo.setFactory(jsonFactory);
GenericJson error = new GenericJson();
error.set("code", status);
error.set("errors", Arrays.asList(errorInfo));
error.setFactory(jsonFactory);
GenericJson errorResponse = new GenericJson();
errorResponse.set("error", error);
errorResponse.setFactory(jsonFactory);
return new MockLowLevelHttpRequest().setResponse(
new MockLowLevelHttpResponse().setContent(errorResponse.toPrettyString())
.setContentType(Json.MEDIA_TYPE).setStatusCode(status));
}
};
HttpRequest request =
transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
request.setThrowExceptionOnExecuteError(false);
HttpResponse response = request.execute();
return GoogleJsonResponseException.from(jsonFactory, response);
}
示例4: 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);
}