当前位置: 首页>>代码示例>>Java>>正文


Java GoogleJsonResponseException.getStatusCode方法代码示例

本文整理汇总了Java中com.google.api.client.googleapis.json.GoogleJsonResponseException.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java GoogleJsonResponseException.getStatusCode方法的具体用法?Java GoogleJsonResponseException.getStatusCode怎么用?Java GoogleJsonResponseException.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.api.client.googleapis.json.GoogleJsonResponseException的用法示例。


在下文中一共展示了GoogleJsonResponseException.getStatusCode方法的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: subscribeTopic

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
/**
 * Sets up a subscription to projects/<code>appName</code>/subscriptions/<code>subName</code>.
 * Ignores error if the subscription already exists.
 * <p/>
 * See <a href="https://cloud.google.com/pubsub/subscriber">cloud.google.com/pubsub/subscriber</a>
 */
Subscription subscribeTopic(String subscriptionName, String topicName) throws IOException {
    String sub = getSubscription(subscriptionName);
    Subscription subscription = new Subscription()
            .setName(sub)
            .setAckDeadlineSeconds(15)
            .setTopic(getTopic(topicName));
    try {
        return pubsub.projects().subscriptions().create(sub, subscription).execute();
    } catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == HttpURLConnection.HTTP_CONFLICT) {
            return subscription;
        } else {
            throw e;
        }
    }
}
 
开发者ID:spac3lord,项目名称:eip,代码行数:23,代码来源:PubSubWrapper.java

示例3: getTable

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
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;
    }
}
 
开发者ID:gymxxx,项目名称:digdag-bq-wait,代码行数:18,代码来源:BqWaitClient.java

示例4: createFirewall

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
/**
 * Adds a firewall rule to the default network so that we can connect to our clients externally.
 */
private void createFirewall() throws IOException {
  Firewall firewallRule = new Firewall()
      .setName("cloud-loadtest-framework-firewall-rule")
      .setDescription("A firewall rule to allow the driver to coordinate load test instances.")
      .setAllowed(ImmutableList.of(
          new Firewall.Allowed()
              .setIPProtocol("tcp")
              .setPorts(Collections.singletonList("5000"))));
  try {
    compute.firewalls().insert(projectName, firewallRule).execute();
  } catch (GoogleJsonResponseException e) {
    if (e.getStatusCode() != ALREADY_EXISTS) {
      throw e;
    }
    compute.firewalls()
        .update(projectName, "cloud-loadtest-framework-firewall-rule", firewallRule).execute();
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:22,代码来源:GCEController.java

示例5: subscribe

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
private void subscribe(Subscription subscription, String cpsSubscriptionName,
    String cpsSubscriptionTopic) throws IOException {
  try {
    pubsub.projects().subscriptions().create(cpsSubscriptionName, subscription).execute();
  } catch (GoogleJsonResponseException e) {
    logger.info("Pubsub Subscribe Error code: " + e.getStatusCode() + "\n" + e.getMessage());
    if (e.getStatusCode() == RESOURCE_CONFLICT) {
      // there is already a subscription and a pull request for this topic.
      // do nothing and return.
      // TODO this condition could change based on the implementation of UNSUBSCRIBE
      logger.info("Cloud PubSub subscription already exists");
    } else if (e.getStatusCode() == RESOURCE_NOT_FOUND) {
      logger.info("Cloud PubSub Topic Not Found");
      createTopic(cpsSubscriptionTopic);
      // possible that subscription name already exists, and might throw an exception.
      // But, we should not treat that as an error.
      subscribe(subscription, cpsSubscriptionName, cpsSubscriptionTopic);
    } else {
      // exception was caused due to some other reason, so we re-throw and do not send a SUBACK.
      // client will re-send the subscription.
      throw e;
    }
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-mqtt-proxy,代码行数:25,代码来源:GcloudPubsub.java

示例6: shouldTerminateSubscription

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
/**
 * If there are no more client subscriptions for the given pubsub topic,
 * the subscription gets terminated, and removed from the subscription map.
 *
 * @param subscriptionName an identifier for the subscription we are attempting to terminate.
 * @return true if the subscription has been terminated, and false otherwise.
 */
public synchronized boolean shouldTerminateSubscription(String subscriptionName) {
  if (!activeSubscriptions.contains(subscriptionName)) {
    try {
      pubsub.projects().subscriptions().delete(subscriptionName);
      return true;
    } catch (GoogleJsonResponseException e) {
      if (e.getStatusCode() == RESOURCE_NOT_FOUND) {
        return true;
      }
    } catch (IOException ioe) {
      // we will return false and the pull task will call this method again when rescheduled.
    }
  }
  return false;
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-mqtt-proxy,代码行数:23,代码来源:GcloudPubsub.java

示例7: createTopic

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
private void createTopic(final String topic) throws IOException {
  try {
    pubsub.projects().topics().create(topic, new Topic()).execute();
  } catch (GoogleJsonResponseException e) {
    // two threads were trying to create topic at the same time
    // first thread created a topic, causing second thread to wait(this method is synchronized)
    // second thread causes an exception since it tries to create an existing topic
    if (e.getStatusCode() == RESOURCE_CONFLICT) {
      logger.info("Topic was created by another thread");
      return ;
    }
    // if it is not a topic conflict(or topic already exists) error,
    // it must be a low level error, and the client should send the PUBLISH packet again for retry
    // we throw the exception, so that we don't send a PUBACK to the client
    throw e;
  }
  logger.info("Google Cloud Pub/Sub Topic Created");
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-mqtt-proxy,代码行数:19,代码来源:GcloudPubsub.java

示例8: createDataset

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
void createDataset(String projectId, Dataset dataset)
        throws IOException
{
    try {
        client.datasets().insert(projectId, dataset)
                .execute();
    }
    catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_CONFLICT) {
            logger.debug("Dataset already exists: {}:{}", dataset.getDatasetReference());
        }
        else {
            throw e;
        }
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:17,代码来源:BqClient.java

示例9: deleteDataset

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
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;
        }
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:19,代码来源:BqClient.java

示例10: createTable

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
void createTable(String projectId, Table table)
        throws IOException
{
    String datasetId = table.getTableReference().getDatasetId();
    try {
        client.tables().insert(projectId, datasetId, table)
                .execute();
    }
    catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == HttpStatusCodes.STATUS_CODE_CONFLICT) {
            logger.debug("Table already exists: {}:{}.{}", projectId, datasetId, table.getTableReference().getTableId());
        }
        else {
            throw e;
        }
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:18,代码来源:BqClient.java

示例11: handleBreakpointQueryError

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
private void handleBreakpointQueryError(
    @NotNull CloudDebugProcessState state, @NotNull Exception ex) {
  String message;
  String projectName = state.getProject().getName();
  if (ex instanceof GoogleJsonResponseException) {
    GoogleJsonResponseException jsonResponseException = (GoogleJsonResponseException) ex;
    if (jsonResponseException.getStatusCode() == HttpURLConnection.HTTP_FORBIDDEN
        || jsonResponseException.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
      message =
          GctBundle.message("clouddebug.background.listener.access.error.message", projectName);
    } else {
      message =
          GctBundle.message(
              "clouddebug.background.listener.general.error.message",
              projectName,
              jsonResponseException.getDetails().getMessage());
    }
  } else {
    message =
        GctBundle.message(
            "clouddebug.background.listener.general.error.message",
            projectName,
            ex.getLocalizedMessage());
  }
  handleBreakpointQueryError(state, message);
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:27,代码来源:CloudDebugGlobalPoller.java

示例12: fetchApplicationForProjectId

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
@NotNull
@VisibleForTesting
Application fetchApplicationForProjectId(
    @NotNull String projectId, @NotNull Credential credential)
    throws IOException, GoogleApiException, AppEngineApplicationNotFoundException {
  try {
    return GoogleApiClientFactory.getInstance()
        .getAppEngineApiClient(credential)
        .apps()
        .get(projectId)
        .execute();
  } catch (GoogleJsonResponseException e) {
    if (e.getStatusCode() == 404) {
      // the application does not exist
      throw new AppEngineApplicationNotFoundException();
    }
    throw GoogleApiException.from(e);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:google-cloud-intellij,代码行数:20,代码来源:GoogleApiClientAppEngineAdminService.java

示例13: run

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
/**
 * Creates a test event, pauses while the user modifies the event in the Calendar UI, and then
 * checks if the event has been modified.
 */
private static void run() throws IOException {
  // Create a test event.
  Event event = Utils.createTestEvent(client, "Test Event");
  System.out.println(String.format("Event created: %s", event.getHtmlLink()));

  // Pause while the user modifies the event in the Calendar UI.
  System.out.println("Modify the event's description and hit enter to continue.");
  System.in.read();

  // Fetch the event again if it's been modified.
  Calendar.Events.Get getRequest = client.events().get("primary", event.getId());
  getRequest.setRequestHeaders(new HttpHeaders().setIfNoneMatch(event.getEtag()));
  try {
    event = getRequest.execute();
    System.out.println("The event was modified, retrieved latest version.");
  } catch (GoogleJsonResponseException e) {
    if (e.getStatusCode() == 304) {
      // A 304 status code, "Not modified", indicates that the etags match, and the event has
      // not been modified since we last retrieved it.
      System.out.println("The event was not modified, using local version.");
    } else {
      throw e;
    }
  }
}
 
开发者ID:googlesamples,项目名称:calendar-sync,代码行数:30,代码来源:ConditionalRetrievalSample.java

示例14: setupTopic

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
/**
 * 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;
        }
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:25,代码来源:InitServlet.java

示例15: createTable

import com.google.api.client.googleapis.json.GoogleJsonResponseException; //导入方法依赖的package包/类
public void createTable(String datasetName, String tableName, List<TableFieldSchema> schemaFields) throws GeneralSecurityException, IOException {
	Bigquery bigquery = GoogleServices.getBigqueryServiceDomainWide();
	
	TableSchema schema = new TableSchema();
	schema.setFields(schemaFields);
	
	Table table = new Table();
	table.setSchema(schema);
	TableReference tableRef = new TableReference();
	tableRef.setDatasetId(datasetName);
	tableRef.setProjectId(AppHelper.getAppId());
	tableRef.setTableId(tableName);
	table.setTableReference(tableRef);
	
	try {
		bigquery.tables().insert(AppHelper.getAppId(), datasetName, table).execute();
	} catch (GoogleJsonResponseException ex) {
		if (ex.getStatusCode() != 409) throw ex;
	}
}
 
开发者ID:andryfailli,项目名称:teampot,代码行数:21,代码来源:AnalyticsService.java


注:本文中的com.google.api.client.googleapis.json.GoogleJsonResponseException.getStatusCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。