本文整理匯總了Java中com.google.api.client.http.HttpResponseException.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponseException.Builder方法的具體用法?Java HttpResponseException.Builder怎麽用?Java HttpResponseException.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.api.client.http.HttpResponseException
的用法示例。
在下文中一共展示了HttpResponseException.Builder方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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);
}
示例3: 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();
}
示例4: shouldHandleTooManyKeysCreated
import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
@Test
public void shouldHandleTooManyKeysCreated() throws IOException {
when(serviceAccountKeyManager.serviceAccountExists(anyString())).thenReturn(true);
final GoogleJsonResponseException resourceExhausted = new GoogleJsonResponseException(
new HttpResponseException.Builder(429, "RESOURCE_EXHAUSTED", new HttpHeaders()),
new GoogleJsonError().set("status", "RESOURCE_EXHAUSTED"));
doThrow(resourceExhausted).when(serviceAccountKeyManager).createJsonKey(any());
doThrow(resourceExhausted).when(serviceAccountKeyManager).createP12Key(any());
exception.expect(InvalidExecutionException.class);
exception.expectMessage("Maximum number of keys on service account reached: " + SERVICE_ACCOUNT);
sut.ensureServiceAccountKeySecret(WORKFLOW_ID.toString(), SERVICE_ACCOUNT);
}
示例5: createNotFoundException
import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
private static GoogleJsonResponseException createNotFoundException() throws Exception {
ByteArrayInputStream inputStream = new ByteArrayInputStream("".getBytes(UTF_8));
HttpResponse response = GoogleJsonResponseExceptionHelper.createHttpResponse(404, inputStream);
HttpResponseException.Builder httpResponseExceptionBuilder =
new HttpResponseException.Builder(response);
httpResponseExceptionBuilder.setStatusCode(404);
httpResponseExceptionBuilder.setStatusMessage("NOT_FOUND");
return new GoogleJsonResponseException(httpResponseExceptionBuilder, null);
}
示例6: from
import com.google.api.client.http.HttpResponseException; //導入方法依賴的package包/類
/**
* Returns a new instance of {@link LenientTokenResponseException}.
* <p>
* If there is a JSON error response, it is parsed using
* {@link TokenErrorResponse}, which can be inspected using
* {@link #getDetails()}. Otherwise, the full response content is read and
* included in the exception message.
* </p>
*
* @param jsonFactory JSON factory
* @param readResponse an HTTP response that has already been read
* @param responseContent the content String of the HTTP response
* @return new instance of {@link TokenErrorResponse}
*/
public static LenientTokenResponseException from(JsonFactory jsonFactory,
HttpResponse readResponse, String responseContent) {
HttpResponseException.Builder builder = new HttpResponseException.Builder(
readResponse.getStatusCode(), readResponse.getStatusMessage(),
readResponse.getHeaders());
// details
Preconditions.checkNotNull(jsonFactory);
TokenErrorResponse details = null;
String detailString = null;
String contentType = readResponse.getContentType();
try {
if (/* !response.isSuccessStatusCode() && */true
&& contentType != null
&& HttpMediaType.equalsIgnoreParameters(Json.MEDIA_TYPE, contentType)) {
details = readResponse
.getRequest()
.getParser()
.parseAndClose(new StringReader(responseContent), TokenErrorResponse.class);
detailString = details.toPrettyString();
} else {
detailString = responseContent;
}
} catch (IOException exception) {
// it would be bad to throw an exception while throwing an exception
exception.printStackTrace();
}
// message
StringBuilder message = HttpResponseException.computeMessageBuffer(readResponse);
if (!com.google.api.client.util.Strings.isNullOrEmpty(detailString)) {
message.append(StringUtils.LINE_SEPARATOR).append(detailString);
builder.setContent(detailString);
}
builder.setMessage(message.toString());
return new LenientTokenResponseException(builder, details);
}