当前位置: 首页>>代码示例>>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;未经允许,请勿转载。