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


Java HttpStatusCodes类代码示例

本文整理汇总了Java中com.google.api.client.http.HttpStatusCodes的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodes类的具体用法?Java HttpStatusCodes怎么用?Java HttpStatusCodes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpStatusCodes类属于com.google.api.client.http包,在下文中一共展示了HttpStatusCodes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleResponse

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
/**
 * @return a URL to continue pushing the BLOB to, or {@code null} if the BLOB already exists on
 *     the registry
 */
@Nullable
@Override
public String handleResponse(Response response) throws RegistryErrorException {
  switch (response.getStatusCode()) {
    case HttpStatusCodes.STATUS_CODE_CREATED:
      // The BLOB exists in the registry.
      return null;

    case HttpURLConnection.HTTP_ACCEPTED:
      return extractLocationHeader(response);

    default:
      throw buildRegistryErrorException(
          "Received unrecognized status code " + response.getStatusCode());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:21,代码来源:BlobPusher.java

示例2: testPush_missingBlobs

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testPush_missingBlobs() throws IOException, RegistryException {
  RegistryClient registryClient = new RegistryClient(null, "gcr.io", "distroless/java");
  ManifestTemplate manifestTemplate = registryClient.pullManifest("latest");

  registryClient = new RegistryClient(null, "localhost:5000", "busybox");
  try {
    registryClient.pushManifest((V22ManifestTemplate) manifestTemplate, "latest");
    Assert.fail("Pushing manifest without its BLOBs should fail");

  } catch (RegistryErrorException ex) {
    HttpResponseException httpResponseException = (HttpResponseException) ex.getCause();
    Assert.assertEquals(
        HttpStatusCodes.STATUS_CODE_BAD_REQUEST, httpResponseException.getStatusCode());
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:17,代码来源:ManifestPusherIntegrationTest.java

示例3: testHandleHttpResponseException

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testHandleHttpResponseException() throws IOException, RegistryErrorException {
  HttpResponseException mockHttpResponseException = Mockito.mock(HttpResponseException.class);
  Mockito.when(mockHttpResponseException.getStatusCode())
      .thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);

  ErrorResponseTemplate emptyErrorResponseTemplate =
      new ErrorResponseTemplate()
          .addError(new ErrorEntryTemplate(ErrorCodes.BLOB_UNKNOWN.name(), "some message"));
  Mockito.when(mockHttpResponseException.getContent())
      .thenReturn(Blobs.writeToString(JsonTemplateMapper.toBlob(emptyErrorResponseTemplate)));

  BlobDescriptor blobDescriptor =
      testBlobChecker.handleHttpResponseException(mockHttpResponseException);

  Assert.assertNull(blobDescriptor);
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:18,代码来源:BlobCheckerTest.java

示例4: testHandleHttpResponseException_hasOtherErrors

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testHandleHttpResponseException_hasOtherErrors()
    throws IOException, RegistryErrorException {
  HttpResponseException mockHttpResponseException = Mockito.mock(HttpResponseException.class);
  Mockito.when(mockHttpResponseException.getStatusCode())
      .thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);

  ErrorResponseTemplate emptyErrorResponseTemplate =
      new ErrorResponseTemplate()
          .addError(new ErrorEntryTemplate(ErrorCodes.BLOB_UNKNOWN.name(), "some message"))
          .addError(new ErrorEntryTemplate(ErrorCodes.MANIFEST_UNKNOWN.name(), "some message"));
  Mockito.when(mockHttpResponseException.getContent())
      .thenReturn(Blobs.writeToString(JsonTemplateMapper.toBlob(emptyErrorResponseTemplate)));

  try {
    testBlobChecker.handleHttpResponseException(mockHttpResponseException);
    Assert.fail("Non-BLOB_UNKNOWN errors should not be handled");

  } catch (HttpResponseException ex) {
    Assert.assertEquals(mockHttpResponseException, ex);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:23,代码来源:BlobCheckerTest.java

示例5: testHandleHttpResponseException_notBlobUnknown

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testHandleHttpResponseException_notBlobUnknown()
    throws IOException, RegistryErrorException {
  HttpResponseException mockHttpResponseException = Mockito.mock(HttpResponseException.class);
  Mockito.when(mockHttpResponseException.getStatusCode())
      .thenReturn(HttpStatusCodes.STATUS_CODE_NOT_FOUND);

  ErrorResponseTemplate emptyErrorResponseTemplate = new ErrorResponseTemplate();
  Mockito.when(mockHttpResponseException.getContent())
      .thenReturn(Blobs.writeToString(JsonTemplateMapper.toBlob(emptyErrorResponseTemplate)));

  try {
    testBlobChecker.handleHttpResponseException(mockHttpResponseException);
    Assert.fail("Non-BLOB_UNKNOWN errors should not be handled");

  } catch (HttpResponseException ex) {
    Assert.assertEquals(mockHttpResponseException, ex);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:20,代码来源:BlobCheckerTest.java

示例6: tsetHandleHttpResponseException_noHeader

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void tsetHandleHttpResponseException_noHeader() throws HttpResponseException {
  Mockito.when(mockHttpResponseException.getStatusCode())
      .thenReturn(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
  Mockito.when(mockHttpResponseException.getHeaders()).thenReturn(mockHeaders);
  Mockito.when(mockHeaders.getAuthenticate()).thenReturn(null);

  try {
    testAuthenticationMethodRetriever.handleHttpResponseException(mockHttpResponseException);
    Assert.fail(
        "Authentication method retriever should fail if 'WWW-Authenticate' header is not found");

  } catch (RegistryErrorException ex) {
    Assert.assertThat(
        ex.getMessage(), CoreMatchers.containsString("'WWW-Authenticate' header not found"));
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:18,代码来源:AuthenticationMethodRetrieverTest.java

示例7: testHandleHttpResponseException_badAuthenticationMethod

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testHandleHttpResponseException_badAuthenticationMethod()
    throws HttpResponseException {
  String authenticationMethod = "bad authentication method";

  Mockito.when(mockHttpResponseException.getStatusCode())
      .thenReturn(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
  Mockito.when(mockHttpResponseException.getHeaders()).thenReturn(mockHeaders);
  Mockito.when(mockHeaders.getAuthenticate()).thenReturn(authenticationMethod);

  try {
    testAuthenticationMethodRetriever.handleHttpResponseException(mockHttpResponseException);
    Assert.fail(
        "Authentication method retriever should fail if 'WWW-Authenticate' header failed to parse");

  } catch (RegistryErrorException ex) {
    Assert.assertThat(
        ex.getMessage(),
        CoreMatchers.containsString(
            "Failed get authentication method from 'WWW-Authenticate' header"));
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:23,代码来源:AuthenticationMethodRetrieverTest.java

示例8: testHandleHttpResponseException_pass

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testHandleHttpResponseException_pass()
    throws RegistryErrorException, HttpResponseException, MalformedURLException {
  String authenticationMethod =
      "Bearer realm=\"https://somerealm\",service=\"someservice\",scope=\"somescope\"";

  Mockito.when(mockHttpResponseException.getStatusCode())
      .thenReturn(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
  Mockito.when(mockHttpResponseException.getHeaders()).thenReturn(mockHeaders);
  Mockito.when(mockHeaders.getAuthenticate()).thenReturn(authenticationMethod);

  RegistryAuthenticator registryAuthenticator =
      testAuthenticationMethodRetriever.handleHttpResponseException(mockHttpResponseException);

  Assert.assertEquals(
      new URL("https://somerealm?service=someservice&scope=repository:someImageName:pull"),
      registryAuthenticator.getAuthenticationUrl());
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:19,代码来源:AuthenticationMethodRetrieverTest.java

示例9: testSimpleRetry

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
public void testSimpleRetry() throws Exception {
    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 3);

    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();
    MockSleeper mockSleeper = new MockSleeper();

    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
        TimeValue.timeValueSeconds(5));

    Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    HttpResponse response = request.execute();

    assertThat(mockSleeper.getCount(), equalTo(3));
    assertThat(response.getStatusCode(), equalTo(200));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:RetryHttpInitializerWrapperTests.java

示例10: testIOExceptionRetry

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
public void testIOExceptionRetry() throws Exception {
    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1, true);

    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();
    MockSleeper mockSleeper = new MockSleeper();
    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
        TimeValue.timeValueMillis(500));

    Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    HttpResponse response = request.execute();

    assertThat(mockSleeper.getCount(), equalTo(1));
    assertThat(response.getStatusCode(), equalTo(200));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RetryHttpInitializerWrapperTests.java

示例11: buildRequest

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
  callCount ++;

  if (!HttpMethods.GET.equals(method) || !expectedUrl.equals(url)) {
    // Throw RuntimeException to fail the test.
    throw new RuntimeException();
  }

  return new MockLowLevelHttpRequest() {
    @Override
    public LowLevelHttpResponse execute() throws IOException {
      MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
      response.setStatusCode(HttpStatusCodes.STATUS_CODE_OK);
      response.setContentType(Json.MEDIA_TYPE);
      response.setContent(jsonResponse);
      return response;
    }
  };
}
 
开发者ID:cloudendpoints,项目名称:endpoints-management-java,代码行数:21,代码来源:DefautKeyUriSupplierTest.java

示例12: getTable

import com.google.api.client.http.HttpStatusCodes; //导入依赖的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

示例13: testNonExistentObjectReturnsEmptyResult

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testNonExistentObjectReturnsEmptyResult() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Objects mockStorageObjects = Mockito.mock(Storage.Objects.class);
  Storage.Objects.Get mockStorageGet = Mockito.mock(Storage.Objects.Get.class);

  GcsPath pattern = GcsPath.fromUri("gs://testbucket/testdirectory/nonexistentfile");
  GoogleJsonResponseException expectedException =
      googleJsonResponseException(HttpStatusCodes.STATUS_CODE_NOT_FOUND,
          "It don't exist", "Nothing here to see");

  when(mockStorage.objects()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.get(pattern.getBucket(), pattern.getObject())).thenReturn(
      mockStorageGet);
  when(mockStorageGet.execute()).thenThrow(expectedException);

  assertEquals(Collections.EMPTY_LIST, gcsUtil.expand(pattern));
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:GcsUtilTest.java

示例14: testAccessDeniedObjectThrowsIOException

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testAccessDeniedObjectThrowsIOException() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Objects mockStorageObjects = Mockito.mock(Storage.Objects.class);
  Storage.Objects.Get mockStorageGet = Mockito.mock(Storage.Objects.Get.class);

  GcsPath pattern = GcsPath.fromUri("gs://testbucket/testdirectory/accessdeniedfile");
  GoogleJsonResponseException expectedException =
      googleJsonResponseException(HttpStatusCodes.STATUS_CODE_FORBIDDEN,
          "Waves hand mysteriously", "These aren't the buckets you're looking for");

  when(mockStorage.objects()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.get(pattern.getBucket(), pattern.getObject())).thenReturn(
      mockStorageGet);
  when(mockStorageGet.execute()).thenThrow(expectedException);

  thrown.expect(IOException.class);
  thrown.expectMessage("Unable to get the file object for path");
  gcsUtil.expand(pattern);
}
 
开发者ID:apache,项目名称:beam,代码行数:26,代码来源:GcsUtilTest.java

示例15: testFileSizeWhenFileNotFoundNonBatch

import com.google.api.client.http.HttpStatusCodes; //导入依赖的package包/类
@Test
public void testFileSizeWhenFileNotFoundNonBatch() throws Exception {
  MockLowLevelHttpResponse notFoundResponse = new MockLowLevelHttpResponse();
  notFoundResponse.setContent("");
  notFoundResponse.setStatusCode(HttpStatusCodes.STATUS_CODE_NOT_FOUND);

  MockHttpTransport mockTransport =
          new MockHttpTransport.Builder().setLowLevelHttpResponse(notFoundResponse).build();

  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  gcsUtil.setStorageClient(new Storage(mockTransport, Transport.getJsonFactory(), null));

  thrown.expect(FileNotFoundException.class);
  gcsUtil.fileSize(GcsPath.fromComponents("testbucket", "testobject"));
}
 
开发者ID:apache,项目名称:beam,代码行数:18,代码来源:GcsUtilTest.java


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