當前位置: 首頁>>代碼示例>>Java>>正文


Java GoogleJsonResponseException.getDetails方法代碼示例

本文整理匯總了Java中com.google.api.client.googleapis.json.GoogleJsonResponseException.getDetails方法的典型用法代碼示例。如果您正苦於以下問題:Java GoogleJsonResponseException.getDetails方法的具體用法?Java GoogleJsonResponseException.getDetails怎麽用?Java GoogleJsonResponseException.getDetails使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.api.client.googleapis.json.GoogleJsonResponseException的用法示例。


在下文中一共展示了GoogleJsonResponseException.getDetails方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: blobExists

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的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;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:22,代碼來源:GoogleCloudStorageBlobStore.java

示例2: getMembersOfGroup

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
@Override
public Set<String> getMembersOfGroup(String groupKey) throws IOException {
  // Documentation for this API call:
  // https://developers.google.com/admin-sdk/directory/v1/reference/members/list
  try {
    ImmutableSet.Builder<String> allMembers = new ImmutableSet.Builder<>();
    Directory.Members.List listRequest =
        directory.members().list(groupKey).setRoles(Role.MEMBER.toString());
    do {
      Members currentPage = listRequest.execute();
      for (Member member : nullToEmpty(currentPage.getMembers())) {
        allMembers.add(member.getEmail());
      }
      listRequest.setPageToken(currentPage.getNextPageToken());
    } while (!Strings.isNullOrEmpty(listRequest.getPageToken()));
    return allMembers.build();
  } catch (GoogleJsonResponseException e) {
    if (e.getDetails() != null
        && e.getDetails().getCode() == SC_NOT_FOUND
        && e.getDetails().getMessage().equals(GROUP_NOT_FOUND_MSG)) {
      return ImmutableSet.of();
    } else {
      throw e;
    }
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:27,代碼來源:DirectoryGroupsConnection.java

示例3: delete

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的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;
}
 
開發者ID:apache,項目名稱:incubator-gobblin,代碼行數:17,代碼來源:GoogleDriveFileSystem.java

示例4: checkGoogleJsonResponseException

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的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;
  }
}
 
開發者ID:googleads,項目名稱:googleads-shopping-samples,代碼行數:19,代碼來源:BaseWorkflowSample.java

示例5: readBlob

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的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;
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:GoogleCloudStorageBlobStore.java

示例6: createStagingLocation

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的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();
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-eclipse,代碼行數:31,代碼來源:GcsDataflowProjectClient.java

示例7: isRateLimitExceeded

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
private boolean isRateLimitExceeded(GoogleJsonResponseException ex) {
	if (ex.getDetails() == null || ex.getDetails().getErrors() == null || ex.getDetails().getErrors().size() == 0) {
		return false;
	}
	String reason = ex.getDetails().getErrors().get(0).getReason();
	return RATE_LIMIT_EXCEEDED_REASON.equals(reason) || USER_RATE_LIMIT_EXCEEDED_REASON.equals(reason);
}
 
開發者ID:cchabanois,項目名稱:mesfavoris,代碼行數:8,代碼來源:GDriveBackOffHttpRequestInitializer.java

示例8: createTopic

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
public static void createTopic(Pubsub pubsub, String topicName) throws IOException {
	if (pubsub == null) {
		logger.info("Not creating topic {} since pubsub has not been configured", topicName);
		return;
	}

	try {
		Topic newTopic = pubsub.projects().topics().create(topicName, new Topic()).execute();
		logger.info("Created: " + newTopic.getName());
	} catch (GoogleJsonResponseException e) {
		final GoogleJsonError details = e.getDetails();
		boolean ignorable = true;

		final Object objectStatus = details.get("status");
		if (objectStatus instanceof String) {
			String status = (String) objectStatus;
			if (!ALREADY_EXISTS.equals(status)) {
				ignorable = false;
			} else {
				logger.info("Topic {} already exists.", topicName);
			}
		}

		if (!ignorable) {
			throw e;
		}
	}
}
 
開發者ID:SignifAi,項目名稱:Spark-PubSub,代碼行數:29,代碼來源:PubsubHelper.java

示例9: from

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
/**
 * Static builder to construct a {@code GoogleApiException} from a {@link
 * GoogleJsonResponseException}
 *
 * @param exception a GoogleJsonResponseException that was thrown by a Google API call
 */
public static GoogleApiException from(GoogleJsonResponseException exception) {
  String message =
      exception.getDetails() != null
          ? exception.getDetails().getMessage()
          : exception.getMessage();
  return new GoogleApiException(message, exception, exception.getStatusCode());
}
 
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-intellij,代碼行數:14,代碼來源:GoogleApiException.java

示例10: getErrorMessage

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
/** Extracts the error message. */
public String getErrorMessage(IOException e) {
  // Prefer to use message from GJRE.
  GoogleJsonResponseException gjre = getJsonResponseExceptionOrNull(e);

  if (gjre != null && gjre.getDetails() != null) {
    return gjre.getDetails().getMessage();
  }
  return e.getMessage();
}
 
開發者ID:GoogleCloudPlatform,項目名稱:bigdata-interop,代碼行數:11,代碼來源:ApiErrorExtractor.java

示例11: getDetails

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
/**
 * If the exception is a GoogleJsonResponseException, get the
 * error details, else return null.
 */
protected GoogleJsonError getDetails(IOException e) {
  if (e instanceof GoogleJsonResponseException) {
    GoogleJsonResponseException ex = (GoogleJsonResponseException) e;
    return ex.getDetails();
  } else {
    return null;
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:bigdata-interop,代碼行數:13,代碼來源:ApiErrorExtractor.java

示例12: enrichReason

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
/**
 * <p>
 * Append error details in the reason (if some details are available).
 * </p>
 * Most of error details are in the Google exception.
 */
private static String enrichReason(String reason, Throwable cause) {
    String prefix = reason != null && !reason.isEmpty() ? reason + " - " : "";
    if (cause instanceof GoogleJsonResponseException) {
        GoogleJsonResponseException googleJsonResponseException = (GoogleJsonResponseException) cause;
        if (googleJsonResponseException.getDetails() != null) {
            return prefix + googleJsonResponseException.getDetails().getMessage();
        }
    }
    return reason;
}
 
開發者ID:jonathanswenson,項目名稱:starschema-bigquery-jdbc,代碼行數:17,代碼來源:BQSQLException.java

示例13: addMemberToGroup

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
@Override
public void addMemberToGroup(String groupKey, String email, Role role) throws IOException {
  // Documentation for this API call:
  // https://developers.google.com/admin-sdk/directory/v1/reference/members/insert
  Member member = new Member();
  member.setEmail(email);
  member.setRole(role.toString());
  try {
    directory.members().insert(groupKey, member).execute();
  } catch (GoogleJsonResponseException e) {
    // If the member is already in the group, ignore the error, get the existing member, and
    // return it.
    GoogleJsonError err = e.getDetails();
    if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(GROUP_NOT_FOUND_MSG)) {
      logger.infofmt(
          e,
          "Creating group %s during addition of member %s because the group doesn't exist.",
          groupKey,
          email);
      createGroup(groupKey);
      addMemberToGroup(groupKey, email, role);
    } else if (err.getCode() == SC_NOT_FOUND && err.getMessage().equals(MEMBER_NOT_FOUND_MSG)) {
      throw new RuntimeException(String.format(
          "Adding member %s to group %s failed because the member wasn't found.",
          email,
          groupKey), e);
    } else if (err.getCode() == SC_CONFLICT
        && err.getMessage().equals(MEMBER_ALREADY_EXISTS_MSG)) {
      // This error case usually happens when an email address is already a member of the gorup,
      // but it is bouncing incoming emails. It won't show up in the members list API call, but
      // will throw a "Member already exists" error message if you attempt to add it again. The
      // correct thing to do is log an info message when this happens and then ignore it.
      logger.infofmt(
          e,
          "Could not add email %s to group %s because it is already a member "
              + "(likely because the email address is bouncing incoming messages).",
          email,
          groupKey);
    } else {
      throw e;
    }
  }
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:44,代碼來源:DirectoryGroupsConnection.java

示例14: subscribe

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
public static void subscribe(Pubsub pubsub, String topicName, String subscriptionName, Integer ackDeadlineSec)
		throws IOException {
	if (pubsub == null) {
		logger.info("Not creating subscription {} for topic {} since pubsub has not been configured", subscriptionName,
				topicName);
		return;
	}

	Subscription subscription = new Subscription()
			// The name of the topic from which this subscription
			// receives messages
			.setTopic(topicName);

	if (ackDeadlineSec != null) {
		// Ackowledgement deadline in second
		subscription.setAckDeadlineSeconds(ackDeadlineSec);
	}

	try {
		Subscription newSubscription = pubsub.projects().subscriptions().create(subscriptionName, subscription)
				.execute();
		logger.info("Created: " + newSubscription.getName());
	} catch (GoogleJsonResponseException e) {
		final GoogleJsonError details = e.getDetails();
		boolean ignorable = true;

		final Object objectStatus = details.get("status");
		if (objectStatus instanceof String) {
			String status = (String) objectStatus;
			if (!ALREADY_EXISTS.equals(status)) {
				ignorable = false;
			} else {
				logger.info("Subscription {} already exists.", subscriptionName);
			}
		}

		if (!ignorable) {
			throw e;
		}
	}
}
 
開發者ID:SignifAi,項目名稱:Spark-PubSub,代碼行數:42,代碼來源:PubsubHelper.java

示例15: getReads

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //導入方法依賴的package包/類
@Override
public ReadIteratorResource getReads(String readsetId, 
    String sequenceName, int sequenceStart, int sequenceEnd) 
        throws IOException, GeneralSecurityException {
  LOG.info("Getting readset " + readsetId + ", sequence " + sequenceName + 
      ", start=" + sequenceStart + ", end=" + sequenceEnd);    
  final Genomics stub = getApi();

  try {
    ReadGroupSet readGroupSet = stub.readgroupsets().get(readsetId).execute();
    String datasetId = readGroupSet.getDatasetId();
    LOG.info("Found readset " + readsetId + ", dataset " + datasetId);
    // Fix up PP in Programs
    
     if (readGroupSet.getReadGroups() != null) { 
      for (ReadGroup readGroup : readGroupSet.getReadGroups()) {
        if (readGroup.getPrograms() != null) {
          for (Program PG : readGroup.getPrograms()) {
            if (PG.getPrevProgramId() != null && PG.getPrevProgramId().length() == 0) {
              PG.setPrevProgramId(null);
            }
          }
        }
      }   
    }
    
    final Map<String, Reference> references = getReferences(readGroupSet);
    final Reference reference = references.get(sequenceName);
    if (reference != null) {
        LOG.info("Reference for sequence name " + sequenceName + " is found, length="
            + String.valueOf(reference.getLength()));
    } else {
      LOG.warning("Reference for sequence name " + sequenceName + " not found");
    }
    LOG.info("Searching for reads in sequence " + sequenceName + " " + 
        String.valueOf(sequenceStart) + "-" + String.valueOf(sequenceEnd));
    com.google.cloud.genomics.gatk.common.UnmappedReads<Read> unmappedReads = null;
    if (sequenceName.isEmpty()) {
      unmappedReads = getUnmappedMatesOfMappedReads(readsetId); 
    }
    Paginator.Reads searchReads = Paginator.Reads.create(stub, ShardBoundary.Requirement.OVERLAPS);
    SearchReadsRequest readRequest = new SearchReadsRequest()
      .setReadGroupSetIds(Arrays.asList(readsetId))
      .setReferenceName(sequenceName)
      .setPageSize(2048);
    if (sequenceStart != 0) {
      readRequest.setStart(Long.valueOf(sequenceStart));
    }
    if (sequenceEnd != 0) {
      readRequest.setEnd(Long.valueOf(sequenceEnd));
    }
    Iterable<Read> reads = searchReads.search(readRequest); 
    
    return new ReadIteratorResource(readGroupSet, 
        Lists.newArrayList(references.values()), unmappedReads, reads);
  } catch (GoogleJsonResponseException ex) {
    LOG.warning("Genomics API call failure: " + ex.getMessage());
    if (ex.getDetails() == null) {
      throw ex;
    }
    throw new IOException(ex.getDetails().getMessage());
  }
}
 
開發者ID:googlegenomics,項目名稱:gatk-tools-java,代碼行數:64,代碼來源:GenomicsDataSource.java


注:本文中的com.google.api.client.googleapis.json.GoogleJsonResponseException.getDetails方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。