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


Java HttpResponseException类代码示例

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


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

示例1: testGetUserUnexpectedHttpError

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
@Test
public void testGetUserUnexpectedHttpError() throws Exception {
  MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
  response.setContent("{\"not\" json}");
  response.setStatusCode(500);
  MockHttpTransport transport = new MockHttpTransport.Builder()
      .setLowLevelHttpResponse(response)
      .build();
  FirebaseUserManager userManager = new FirebaseUserManager(gson, transport, credentials);
  try {
    userManager.getUserById("testuser");
    fail("No error thrown for JSON error");
  }  catch (FirebaseAuthException e) {
    assertTrue(e.getCause() instanceof HttpResponseException);
    assertEquals("Unexpected HTTP response with status: 500; body: {\"not\" json}",
        e.getMessage());
    assertEquals(FirebaseUserManager.INTERNAL_ERROR, e.getErrorCode());
  }
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:20,代码来源:FirebaseUserManagerTest.java

示例2: registerMetric_fetchesStackdriverDefinition

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
@Test
public void registerMetric_fetchesStackdriverDefinition() throws Exception {
  // Stackdriver throws an Exception with the status message "ALREADY_EXISTS" when you try to
  // register a metric that's already been registered, so we fake one here.
  ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8));
  HttpResponse response = GoogleJsonResponseExceptionHelper.createHttpResponse(400, inputStream);
  HttpResponseException.Builder httpResponseExceptionBuilder =
      new HttpResponseException.Builder(response);
  httpResponseExceptionBuilder.setStatusCode(400);
  httpResponseExceptionBuilder.setStatusMessage("ALREADY_EXISTS");
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(httpResponseExceptionBuilder, null);
  when(metricDescriptorCreate.execute()).thenThrow(exception);
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);

  writer.registerMetric(metric);

  verify(client.projects().metricDescriptors().get("metric")).execute();
}
 
开发者ID:google,项目名称:java-monitoring-client-library,代码行数:21,代码来源:StackdriverWriterTest.java

示例3: registerMetric_rethrowsException

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
@Test
public void registerMetric_rethrowsException() throws Exception {
  ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8));
  HttpResponse response = GoogleJsonResponseExceptionHelper.createHttpResponse(400, inputStream);
  HttpResponseException.Builder httpResponseExceptionBuilder =
      new HttpResponseException.Builder(response);
  httpResponseExceptionBuilder.setStatusCode(404);
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(httpResponseExceptionBuilder, null);
  when(metricDescriptorCreate.execute()).thenThrow(exception);
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);

  assertThrows(GoogleJsonResponseException.class, () -> writer.registerMetric(metric));
  assertThat(exception.getStatusCode()).isEqualTo(404);
}
 
开发者ID:google,项目名称:java-monitoring-client-library,代码行数:17,代码来源:StackdriverWriterTest.java

示例4: getEncodedTimeSeries_nullLabels_encodes

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
@Test
public void getEncodedTimeSeries_nullLabels_encodes() throws Exception {
  ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8));
  HttpResponse response = GoogleJsonResponseExceptionHelper.createHttpResponse(400, inputStream);
  HttpResponseException.Builder httpResponseExceptionBuilder =
      new HttpResponseException.Builder(response);
  httpResponseExceptionBuilder.setStatusCode(400);
  httpResponseExceptionBuilder.setStatusMessage("ALREADY_EXISTS");
  GoogleJsonResponseException exception =
      new GoogleJsonResponseException(httpResponseExceptionBuilder, null);
  when(metricDescriptorCreate.execute()).thenThrow(exception);
  when(metricDescriptorGet.execute())
      .thenReturn(new MetricDescriptor().setName("foo").setLabels(null));
  StackdriverWriter writer =
      new StackdriverWriter(client, PROJECT, MONITORED_RESOURCE, MAX_QPS, MAX_POINTS_PER_REQUEST);
  writer.registerMetric(metric);

  TimeSeries timeSeries =
      writer.getEncodedTimeSeries(
          MetricPoint.create(metric, ImmutableList.of("foo"), Instant.ofEpochMilli(1337), 10L));

  assertThat(timeSeries.getMetric().getLabels()).isEmpty();
}
 
开发者ID:google,项目名称:java-monitoring-client-library,代码行数:24,代码来源:StackdriverWriterTest.java

示例5: testPush_missingBlobs

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

示例6: testHandleHttpResponseException

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

示例7: testHandleHttpResponseException_hasOtherErrors

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

示例8: testHandleHttpResponseException_notBlobUnknown

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

示例9: tsetHandleHttpResponseException_noHeader

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

示例10: testHandleHttpResponseException_badAuthenticationMethod

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

示例11: testHandleHttpResponseException_pass

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

示例12: map

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
@Override
public BackgroundException map(final IOException failure) {
    final StringBuilder buffer = new StringBuilder();
    if(failure instanceof GoogleJsonResponseException) {
        final GoogleJsonResponseException error = (GoogleJsonResponseException) failure;
        this.append(buffer, error.getDetails().getMessage());
        switch(error.getDetails().getCode()) {
            case HttpStatus.SC_FORBIDDEN:
                final List<GoogleJsonError.ErrorInfo> errors = error.getDetails().getErrors();
                for(GoogleJsonError.ErrorInfo info : errors) {
                    if("usageLimits".equals(info.getDomain())) {
                        return new RetriableAccessDeniedException(buffer.toString(), Duration.ofSeconds(5), failure);
                    }
                }
                break;
        }
    }
    if(failure instanceof HttpResponseException) {
        final HttpResponseException response = (HttpResponseException) failure;
        this.append(buffer, response.getStatusMessage());
        return new HttpResponseExceptionMappingService().map(new org.apache.http.client
                .HttpResponseException(response.getStatusCode(), buffer.toString()));
    }
    return super.map(failure);
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:26,代码来源:DriveExceptionMappingService.java

示例13: convertException

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
/**
 * @deprecated As of xero-java-sdk version 0.6.0, to be removed
 * in favour of {@link XeroExceptionHandler#convertException(IOException)}
 */
protected RuntimeException convertException(IOException ioe) {
    if (ioe instanceof HttpResponseException) {
        HttpResponseException googleException = (HttpResponseException) ioe;

        if (googleException.getStatusCode() == 400 ||
            googleException.getStatusCode() == 401 ||
            googleException.getStatusCode() == 404 ||
            googleException.getStatusCode() == 500 ||
            googleException.getStatusCode() == 503) {
            return newApiException(googleException);
        } else {
            return newApiException(googleException);
        }
    }
    return new RuntimeException(ioe);
}
 
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:21,代码来源:XeroClient.java

示例14: execute

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
public boolean execute() throws IOException {
  try {
    HttpResponse response = request.execute();

    isSuccess = response.isSuccessStatusCode();

    if (isSuccess) {
      Map<String, String> oauthKeys = getQueryMap(response.parseAsString());

      this.token = oauthKeys.get("oauth_token");
      this.tokenSecret = oauthKeys.get("oauth_token_secret");
      this.sessionHandle = oauthKeys.get("oauth_session_handle");
      this.tokenTimestamp = System.currentTimeMillis() / 1000l;
      isSuccess = true;
    } else {

    }
  } catch (HttpResponseException e) {

    Map<String, String> oauthError = getQueryMap(e.getMessage());
    this.problem = oauthError.get("oauth_problem");
    this.advice = oauthError.get("oauth_problem_advice");
    isSuccess = false;
  }
  return isSuccess;
}
 
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:27,代码来源:OAuthAccessToken.java

示例15: convertException

import com.google.api.client.http.HttpResponseException; //导入依赖的package包/类
/**
 * For backwards comparability with xero-java-sdk version 0.6.0 keep the old way of handling exceptions
 *
 * @param ioe exception to convert
 * @return the converted exception
 */
public XeroApiException convertException(IOException ioe) {
    if (ioe instanceof HttpResponseException) {
        HttpResponseException httpResponseException = (HttpResponseException) ioe;
        if (httpResponseException.getStatusCode() == 400) {
            return handleBadRequest(httpResponseException);
        } else if (httpResponseException.getStatusCode() == 401 ||
            httpResponseException.getStatusCode() == 404 ||
            httpResponseException.getStatusCode() == 500 ||
            httpResponseException.getStatusCode() == 503) {
            return newApiException(httpResponseException);
        } else {
            return newApiException(httpResponseException);
        }
    }
    throw new XeroClientException(ioe.getMessage(), ioe);
}
 
开发者ID:XeroAPI,项目名称:Xero-Java,代码行数:23,代码来源:XeroExceptionHandler.java


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