本文整理汇总了Java中com.google.api.client.http.HttpStatusCodes.STATUS_CODE_NOT_FOUND属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodes.STATUS_CODE_NOT_FOUND属性的具体用法?Java HttpStatusCodes.STATUS_CODE_NOT_FOUND怎么用?Java HttpStatusCodes.STATUS_CODE_NOT_FOUND使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.api.client.http.HttpStatusCodes
的用法示例。
在下文中一共展示了HttpStatusCodes.STATUS_CODE_NOT_FOUND属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTable
Optional<Table> getTable(String projectId, String datasetId, String tableId, boolean rowsExist)
throws IOException
{
try {
Table ret = client.tables().get(projectId, datasetId, tableId).execute();
if(rowsExist && ret.getNumRows().compareTo(BigInteger.ZERO) <= 0) {
return Optional.absent();
}
return Optional.of(ret);
}
catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
return Optional.absent();
}
throw e;
}
}
示例2: deleteDataset
void deleteDataset(String projectId, String datasetId)
throws IOException
{
if (datasetExists(projectId, datasetId)) {
deleteTables(projectId, datasetId);
try {
client.datasets().delete(projectId, datasetId).execute();
}
catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
// Already deleted
return;
}
throw e;
}
}
}
示例3: setupTopic
/**
* Creates a Cloud Pub/Sub topic if it doesn't exist.
*
* @param client Pubsub client object.
* @throws IOException when API calls to Cloud Pub/Sub fails.
*/
private void setupTopic(final Pubsub client) throws IOException {
String fullName = String.format("projects/%s/topics/%s",
PubsubUtils.getProjectId(),
PubsubUtils.getAppTopicName());
try {
client.projects().topics().get(fullName).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
// Create the topic if it doesn't exist
client.projects().topics()
.create(fullName, new Topic())
.execute();
} else {
throw e;
}
}
}
示例4: handleHttpResponseException
@Override
public BlobDescriptor handleHttpResponseException(HttpResponseException httpResponseException)
throws RegistryErrorException, HttpResponseException {
if (httpResponseException.getStatusCode() != HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
throw httpResponseException;
}
// Finds a BLOB_UNKNOWN error response code.
String errorContent = httpResponseException.getContent();
if (errorContent == null) {
// TODO: The Google HTTP client gives null content for HEAD requests. Make the content never be null, even for HEAD requests.
return null;
} else {
try {
ErrorResponseTemplate errorResponse =
JsonTemplateMapper.readJson(errorContent, ErrorResponseTemplate.class);
List<ErrorEntryTemplate> errors = errorResponse.getErrors();
if (errors.size() == 1) {
ErrorCodes errorCode = ErrorCodes.valueOf(errors.get(0).getCode());
if (errorCode.equals(ErrorCodes.BLOB_UNKNOWN)) {
return null;
}
}
} catch (IOException ex) {
throw new RegistryErrorExceptionBuilder(getActionDescription(), ex)
.addReason("Failed to parse registry error response body")
.build();
}
}
// BLOB_UNKNOWN was not found as a error response code.
throw httpResponseException;
}
示例5: createTopic
/** Create a topic if it doesn't exist. */
public static void createTopic(Pubsub client, String fullTopicName) throws IOException {
try {
client.projects().topics().get(fullTopicName).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
Topic topic = client.projects().topics().create(fullTopicName, new Topic()).execute();
System.out.printf("Topic %s was created.\n", topic.getName());
}
}
}
示例6: createTopic
/**
* Create a topic if it doesn't exist.
*/
public static void createTopic(Pubsub client, String fullTopicName)
throws IOException {
try {
client.projects().topics().get(fullTopicName).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
Topic topic = client.projects().topics()
.create(fullTopicName, new Topic())
.execute();
System.out.printf("Topic %s was created.\n", topic.getName());
}
}
}
示例7: createTopic
/**
* Create a topic if it doesn't exist.
*/
public static void createTopic(Pubsub client, String fullTopicName)
throws IOException {
try {
client.projects().topics().get(fullTopicName).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
Topic topic = client.projects().topics()
.create(fullTopicName, new Topic())
.execute();
System.out.printf("Topic %s was created.%n", topic.getName());
}
}
}
示例8: deleteTable
void deleteTable(String projectId, String datasetId, String tableId)
throws IOException
{
try {
client.tables().delete(projectId, datasetId, tableId).execute();
}
catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
// Already deleted
return;
}
throw e;
}
}
示例9: datasetExists
boolean datasetExists(String projectId, String datasetId)
throws IOException
{
try {
client.datasets().get(projectId, datasetId).execute();
return true;
}
catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
return false;
}
throw e;
}
}
示例10: stat
Optional<StorageObject> stat(String bucket, String object)
throws IOException
{
try {
return Optional.of(client.objects()
.get(bucket, object)
.execute());
}
catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
return Optional.absent();
}
throw e;
}
}
示例11: tableExists
static boolean tableExists(Bigquery bq, String projectId, String datasetId, String tableId)
throws IOException
{
try {
bq.tables().get(projectId, datasetId, tableId).execute();
return true;
}
catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
return false;
}
throw e;
}
}
示例12: datasetExists
static boolean datasetExists(Bigquery bq, String projectId, String datasetId)
throws IOException
{
try {
bq.datasets().get(projectId, datasetId).execute();
return true;
}
catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
return false;
}
throw e;
}
}
示例13: setupSubscription
/**
* Creates a Cloud Pub/Sub subscription if it doesn't exist.
*
* @param client Pubsub client object.
* @throws IOException when API calls to Cloud Pub/Sub fails.
*/
private void setupSubscription(final Pubsub client) throws IOException {
String fullName = String.format("projects/%s/subscriptions/%s",
PubsubUtils.getProjectId(),
PubsubUtils.getAppSubscriptionName());
try {
client.projects().subscriptions().get(fullName).execute();
} catch (GoogleJsonResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
// Create the subscription if it doesn't exist
String fullTopicName = String.format("projects/%s/topics/%s",
PubsubUtils.getProjectId(),
PubsubUtils.getAppTopicName());
PushConfig pushConfig = new PushConfig()
.setPushEndpoint(PubsubUtils.getAppEndpointUrl());
Subscription subscription = new Subscription()
.setTopic(fullTopicName)
.setPushConfig(pushConfig);
client.projects().subscriptions()
.create(fullName, subscription)
.execute();
} else {
throw e;
}
}
}
示例14: main
public static void main(String[] args)
throws IOException, GeneralSecurityException {
Pubsub pubsubClient = ServiceAccountConfiguration.createPubsubClient(
Settings.getSettings().getServiceAccountEmail(),
Settings.getSettings().getServiceAccountP12KeyPath());
String topicName = Settings.getSettings().getTopicName();
try {
Topic topic = pubsubClient
.projects()
.topics()
.get(topicName)
.execute();
LOG.info("The topic " + topicName + " exists: " + topic.toPrettyString());
} catch (HttpResponseException e) {
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
// The topic doesn't exist
LOG.info("The topic " + topicName + " doesn't exist, creating it");
// TODO(kirillov): add explicit error handling here
pubsubClient
.projects()
.topics()
.create(topicName, new Topic())
.execute();
LOG.info("The topic " + topicName + " created");
}
}
ImmutableList.Builder<PubsubMessage> listBuilder = ImmutableList.builder();
EmmPubsub.MdmPushNotification mdmPushNotification = EmmPubsub.MdmPushNotification.newBuilder()
.setEnterpriseId("12321321")
.setEventNotificationSentTimestampMillis(System.currentTimeMillis())
.addProductApprovalEvent(EmmPubsub.ProductApprovalEvent.newBuilder()
.setApproved(EmmPubsub.ProductApprovalEvent.ApprovalStatus.UNAPPROVED)
.setProductId("app:com.android.chrome"))
.build();
PublishRequest publishRequest = new PublishRequest()
.setMessages(ImmutableList.of(new PubsubMessage()
.encodeData(mdmPushNotification.toByteArray())));
LOG.info("Publishing a request: " + publishRequest.toPrettyString());
pubsubClient
.projects()
.topics()
.publish(topicName, publishRequest)
.execute();
}
示例15: ensureSubscriptionExists
/**
* Verifies that the subscription with the name defined in settings file actually exists and
* points to a correct topic defined in the same settings file. If the subscription doesn't
* exist, it will be created.
*/
private static void ensureSubscriptionExists(Pubsub client) throws IOException {
// First we check if the subscription with this name actually exists.
Subscription subscription = null;
String topicName = Settings.getSettings().getTopicName();
String subName = Settings.getSettings().getSubscriptionName();
LOG.info("Will be using topic name: " + topicName + ", subscription name: " + subName);
try {
LOG.info("Trying to get subscription named " + subName);
subscription = client
.projects()
.subscriptions()
.get(subName)
.execute();
Preconditions.checkArgument(
subscription.getTopic().equals(topicName),
"Subscription %s already exists but points to a topic %s and not %s." +
"Please specify a different subscription name or delete this subscription",
subscription.getName(),
subscription.getTopic(),
topicName);
LOG.info("Will be re-using existing subscription: " + subscription.toPrettyString());
} catch (HttpResponseException e) {
// Subscription not found
if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
LOG.info("Subscription doesn't exist, will try to create " + subName);
// Creating subscription
subscription = client
.projects()
.subscriptions()
.create(subName, new Subscription()
.setTopic(topicName) // Name of the topic it subscribes to
.setAckDeadlineSeconds(600)
.setPushConfig(new PushConfig()
// FQDN with valid SSL certificate
.setPushEndpoint(Settings.getSettings().getPushEndpoint())))
.execute();
LOG.info("Created: " + subscription.toPrettyString());
}
}
}