本文整理汇总了Java中com.google.api.client.googleapis.json.GoogleJsonError类的典型用法代码示例。如果您正苦于以下问题:Java GoogleJsonError类的具体用法?Java GoogleJsonError怎么用?Java GoogleJsonError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GoogleJsonError类属于com.google.api.client.googleapis.json包,在下文中一共展示了GoogleJsonError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: blobExists
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
/**
* Returns true if the blob exists in the bucket
*
* @param blobName name of the blob
* @return true if the blob exists, false otherwise
*/
boolean blobExists(String blobName) throws IOException {
try {
StorageObject blob = SocketAccess.doPrivilegedIOException(() -> client.objects().get(bucket, blobName).execute());
if (blob != null) {
return Strings.hasText(blob.getId());
}
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
return false;
}
throw e;
}
return false;
}
示例2: map
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Override
public BackgroundException map(final IOException failure) {
final StringBuilder buffer = new StringBuilder();
if(failure instanceof GoogleJsonResponseException) {
final GoogleJsonResponseException error = (GoogleJsonResponseException) failure;
this.append(buffer, error.getDetails().getMessage());
switch(error.getDetails().getCode()) {
case HttpStatus.SC_FORBIDDEN:
final List<GoogleJsonError.ErrorInfo> errors = error.getDetails().getErrors();
for(GoogleJsonError.ErrorInfo info : errors) {
if("usageLimits".equals(info.getDomain())) {
return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(5), failure);
}
}
break;
}
}
if(failure instanceof HttpResponseException) {
final HttpResponseException response = (HttpResponseException) failure;
this.append(buffer, response.getStatusMessage());
return new HttpResponseExceptionMappingService().map(new org.apache.http.client
.HttpResponseException(response.getStatusCode(), buffer.toString()));
}
return super.map(failure);
}
示例3: shouldHandleTooManyKeysCreated
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Test
public void shouldHandleTooManyKeysCreated() throws IOException {
when(serviceAccountKeyManager.serviceAccountExists(anyString())).thenReturn(true);
final GoogleJsonResponseException resourceExhausted = new GoogleJsonResponseException(
new HttpResponseException.Builder(429, "RESOURCE_EXHAUSTED", new HttpHeaders()),
new GoogleJsonError().set("status", "RESOURCE_EXHAUSTED"));
doThrow(resourceExhausted).when(serviceAccountKeyManager).createJsonKey(any());
doThrow(resourceExhausted).when(serviceAccountKeyManager).createP12Key(any());
exception.expect(InvalidExecutionException.class);
exception.expectMessage("Maximum number of keys on service account reached: " + SERVICE_ACCOUNT);
sut.ensureServiceAccountKeySecret(WORKFLOW_ID.toString(), SERVICE_ACCOUNT);
}
示例4: create_adminApiNotEnabled
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Test
public void create_adminApiNotEnabled() throws IOException {
ErrorInfo error = new ErrorInfo();
error.setReason(SslSocketFactory.ADMIN_API_NOT_ENABLED_REASON);
GoogleJsonError details = new GoogleJsonError();
details.setErrors(ImmutableList.of(error));
when(adminApiInstancesGet.execute())
.thenThrow(
new GoogleJsonResponseException(
new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
details));
SslSocketFactory sslSocketFactory =
new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
try {
sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
fail("Expected RuntimeException");
} catch (RuntimeException e) {
// TODO(berezv): should we throw something more specific than RuntimeException?
assertThat(e.getMessage()).contains("Cloud SQL API is not enabled");
}
}
示例5: create_notAuthorizedToGetInstance
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Test
public void create_notAuthorizedToGetInstance() throws IOException {
ErrorInfo error = new ErrorInfo();
error.setReason(SslSocketFactory.INSTANCE_NOT_AUTHORIZED_REASON);
GoogleJsonError details = new GoogleJsonError();
details.setErrors(ImmutableList.of(error));
when(adminApiInstancesGet.execute())
.thenThrow(
new GoogleJsonResponseException(
new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
details));
SslSocketFactory sslSocketFactory =
new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
try {
sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
fail("Expected RuntimeException");
} catch (RuntimeException e) {
// TODO(berezv): should we throw something more specific than RuntimeException?
assertThat(e.getMessage()).contains("not authorized");
}
}
示例6: create_notAuthorizedToCreateEphemeralCertificate
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Test
public void create_notAuthorizedToCreateEphemeralCertificate() throws IOException {
ErrorInfo error = new ErrorInfo();
error.setReason(SslSocketFactory.INSTANCE_NOT_AUTHORIZED_REASON);
GoogleJsonError details = new GoogleJsonError();
details.setErrors(ImmutableList.of(error));
when(adminApiSslCertsCreateEphemeral.execute())
.thenThrow(
new GoogleJsonResponseException(
new HttpResponseException.Builder(403, "Forbidden", new HttpHeaders()),
details));
SslSocketFactory sslSocketFactory =
new SslSocketFactory(new Clock(), clientKeyPair, credential, adminApi, 3307);
try {
sslSocketFactory.create(INSTANCE_CONNECTION_STRING);
fail();
} catch (RuntimeException e) {
// TODO(berezv): should we throw something more specific than RuntimeException?
assertThat(e.getMessage()).contains("Unable to obtain ephemeral certificate");
}
}
示例7: testItemNotFound
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
/**
* Validates itemNotFound().
*/
@Test
public void testItemNotFound() {
// Check success cases.
assertTrue(errorExtractor.itemNotFound(notFound));
GoogleJsonError gje = new GoogleJsonError();
gje.setCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);
assertTrue(errorExtractor.itemNotFound(gje));
assertTrue(errorExtractor.itemNotFound(new IOException(notFound)));
assertTrue(errorExtractor.itemNotFound(new IOException(new IOException(notFound))));
// Check failure case.
assertFalse(errorExtractor.itemNotFound(statusOk));
assertFalse(errorExtractor.itemNotFound(new IOException()));
assertFalse(errorExtractor.itemNotFound(new IOException(new IOException())));
}
示例8: delete
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Override
public boolean delete(Path path, boolean recursive) throws IOException {
Preconditions.checkArgument(recursive, "Non-recursive is not supported.");
String fileId = toFileId(path);
LOG.debug("Deleting file: " + fileId);
try {
client.files().delete(fileId).execute();
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
if (404 == error.getCode()) { //Non-existing file id
return false;
}
throw e;
}
return true;
}
示例9: logAndShow
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
/**
* Logs the given throwable and shows an error alert dialog with its
* message.
*
* @param activity
* activity
* @param tag
* log tag to use
* @param t
* throwable to log and show
*/
public static void logAndShow(Activity activity, String tag, Throwable t) {
Log.e(tag, "Error", t);
String message = t.getMessage();
if (t instanceof GoogleJsonResponseException) {
GoogleJsonError details = ((GoogleJsonResponseException) t)
.getDetails();
if (details != null) {
message = details.getMessage();
}
} else if (t.getCause() instanceof OperationCanceledException) {
message = ((OperationCanceledException) t.getCause()).getMessage();
} else if (t.getCause() instanceof GoogleAuthException) {
message = ((GoogleAuthException) t.getCause()).getMessage();
} else if (t instanceof IOException) {
if (t.getMessage() == null) {
message = "IOException";
}
}
Log.d(tag, message);
ToastHelper.showErrorToast(activity,
activity.getResources().getString(R.string.error));
}
示例10: checkGoogleJsonResponseException
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
protected static void checkGoogleJsonResponseException(GoogleJsonResponseException e)
throws GoogleJsonResponseException {
GoogleJsonError err = e.getDetails();
// err can be null if response is not JSON
if (err != null) {
// For errors in the 4xx range, print out the errors and continue normally.
if (err.getCode() >= 400 && err.getCode() < 500) {
System.out.printf("There are %d error(s)%n", err.getErrors().size());
for (ErrorInfo info : err.getErrors()) {
System.out.printf("- [%s] %s%n", info.getReason(), info.getMessage());
}
} else {
throw e;
}
} else {
throw e;
}
}
示例11: readBlob
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
/**
* Returns an {@link java.io.InputStream} for a given blob
*
* @param blobName name of the blob
* @return an InputStream
*/
InputStream readBlob(String blobName) throws IOException {
try {
return SocketAccess.doPrivilegedIOException(() -> {
Storage.Objects.Get object = client.objects().get(bucket, blobName);
return object.executeMediaAsInputStream();
});
} catch (GoogleJsonResponseException e) {
GoogleJsonError error = e.getDetails();
if ((e.getStatusCode() == HTTP_NOT_FOUND) || ((error != null) && (error.getCode() == HTTP_NOT_FOUND))) {
throw new NoSuchFileException(e.getMessage());
}
throw e;
}
}
示例12: notFoundResponseIsNotPermissionDenied
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Test
public void notFoundResponseIsNotPermissionDenied() throws Exception {
assertThat(GcpUtil.isPermissionDenied(new GoogleJsonResponseException(
new Builder(404, "Not Found", new HttpHeaders()), new GoogleJsonError())), is(false));
assertThat(GcpUtil.isPermissionDenied(new GoogleJsonResponseException(
new Builder(404, "Not Found", new HttpHeaders()), null)), is(false));
}
示例13: notFoundResponseIsNotPResourceExhausted
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
@Test
public void notFoundResponseIsNotPResourceExhausted() throws Exception {
assertThat(GcpUtil.isResourceExhausted(new GoogleJsonResponseException(
new Builder(404, "Not Found", new HttpHeaders()), new GoogleJsonError())), is(false));
assertThat(GcpUtil.isResourceExhausted(new GoogleJsonResponseException(
new Builder(404, "Not Found", new HttpHeaders()), null)), is(false));
}
示例14: createStagingLocation
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
/**
* Uses the provided specification for the staging location, creating it if it does not already
* exist. This may be a long-running blocking operation.
*/
public StagingLocationVerificationResult createStagingLocation(
String projectId, String stagingLocation, IProgressMonitor progressMonitor) {
SubMonitor monitor = SubMonitor.convert(progressMonitor, 2);
String bucketName = toGcsBucketName(stagingLocation);
if (locationIsAccessible(stagingLocation)) { // bucket already exists
return new StagingLocationVerificationResult(
String.format("Bucket %s exists", bucketName), true);
}
monitor.worked(1);
// else create the bucket
try {
Bucket newBucket = new Bucket();
newBucket.setName(bucketName);
gcsClient.buckets().insert(projectId, newBucket).execute();
return new StagingLocationVerificationResult(
String.format("Bucket %s created", bucketName), true);
} catch (GoogleJsonResponseException ex) {
GoogleJsonError error = ex.getDetails();
return new StagingLocationVerificationResult(error.getMessage(), false);
} catch (IOException e) {
return new StagingLocationVerificationResult(e.getMessage(), false);
} finally {
monitor.done();
}
}
示例15: errorWithReasonAndStatus
import com.google.api.client.googleapis.json.GoogleJsonError; //导入依赖的package包/类
/** A helper that generates the error JSON payload that Google APIs produce. */
private static GoogleJsonErrorContainer errorWithReasonAndStatus(String reason, int status) {
ErrorInfo info = new ErrorInfo();
info.setReason(reason);
info.setDomain("global");
// GoogleJsonError contains one or more ErrorInfo objects; our utiities read the first one.
GoogleJsonError error = new GoogleJsonError();
error.setErrors(ImmutableList.of(info));
error.setCode(status);
error.setMessage(reason);
// The actual JSON response is an error container.
GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
container.setError(error);
return container;
}