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


Java HttpStatusCodes.STATUS_CODE_NOT_FOUND属性代码示例

本文整理汇总了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;
    }
}
 
开发者ID:gymxxx,项目名称:digdag-bq-wait,代码行数:17,代码来源:BqWaitClient.java

示例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;
        }
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:18,代码来源:BqClient.java

示例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;
        }
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:24,代码来源:InitServlet.java

示例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;
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:34,代码来源:BlobChecker.java

示例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());
    }
  }
}
 
开发者ID:mdvorsky,项目名称:DataflowSME,代码行数:11,代码来源:InjectorUtils.java

示例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());
    }
  }
}
 
开发者ID:davorbonaci,项目名称:beam-portability-demo,代码行数:16,代码来源:InjectorUtils.java

示例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());
    }
  }
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:InjectorUtils.java

示例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;
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:14,代码来源:BqClient.java

示例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;
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:14,代码来源:BqClient.java

示例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;
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:15,代码来源:GcsClient.java

示例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;
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:14,代码来源:GcpUtil.java

示例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;
    }
}
 
开发者ID:treasure-data,项目名称:digdag,代码行数:14,代码来源:GcpUtil.java

示例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;
        }
    }
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-pubsub-samples-java,代码行数:32,代码来源:InitServlet.java

示例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();
}
 
开发者ID:google,项目名称:play-work,代码行数:53,代码来源:TestPublisher.java

示例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());
    }
  }
}
 
开发者ID:google,项目名称:play-work,代码行数:53,代码来源:PushSubscriber.java


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