use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class EventStreamAsyncResponseTransformer method transformEventMessage.
private Iterable<EventT> transformEventMessage(Message message) throws Exception {
SdkHttpFullResponse response = adaptMessageToResponse(message, false);
if (message.getHeaders().get(":event-type").getString().equals("initial-response")) {
ResponseT initialResponse = initialResponseHandler.handle(response, attributesFactory.get());
eventStreamResponseHandler.responseReceived(initialResponse);
log.debug(() -> getLogPrefix() + "Decoded initial response: " + initialResponse);
return emptyList();
}
EventT event = eventResponseHandler.handle(response, attributesFactory.get());
log.debug(() -> getLogPrefix() + "Decoded event: " + event);
return singleton(event);
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class CoreMetricsTest method testApiCall_serviceReturnsError_errorInfoIncludedInMetrics.
@Test
public void testApiCall_serviceReturnsError_errorInfoIncludedInMetrics() throws IOException {
AbortableInputStream content = contentStream("{}");
SdkHttpFullResponse httpResponse = SdkHttpFullResponse.builder().statusCode(500).putHeader("x-amz-request-id", REQUEST_ID).putHeader("x-amz-id-2", EXTENDED_REQUEST_ID).putHeader("X-Amzn-Errortype", "EmptyModeledException").content(content).build();
HttpExecuteResponse response = mockExecuteResponse(httpResponse);
ExecutableHttpRequest mockExecuteRequest = mock(ExecutableHttpRequest.class);
when(mockExecuteRequest.call()).thenReturn(response);
when(mockHttpClient.prepareRequest(any(HttpExecuteRequest.class))).thenReturn(mockExecuteRequest);
thrown.expect(EmptyModeledException.class);
try {
client.allTypes();
} finally {
ArgumentCaptor<MetricCollection> collectionCaptor = ArgumentCaptor.forClass(MetricCollection.class);
verify(mockPublisher).publish(collectionCaptor.capture());
MetricCollection capturedCollection = collectionCaptor.getValue();
assertThat(capturedCollection.children()).hasSize(MAX_RETRIES + 1);
assertThat(capturedCollection.metricValues(CoreMetric.RETRY_COUNT)).containsExactly(MAX_RETRIES);
assertThat(capturedCollection.metricValues(CoreMetric.API_CALL_SUCCESSFUL)).containsExactly(false);
for (MetricCollection requestMetrics : capturedCollection.children()) {
// A service exception is still a successful HTTP execution so
// we should still have HTTP metrics as well.
assertThat(requestMetrics.metricValues(HttpMetric.HTTP_STATUS_CODE)).containsExactly(500);
assertThat(requestMetrics.metricValues(CoreMetric.AWS_REQUEST_ID)).containsExactly(REQUEST_ID);
assertThat(requestMetrics.metricValues(CoreMetric.AWS_EXTENDED_REQUEST_ID)).containsExactly(EXTENDED_REQUEST_ID);
assertThat(requestMetrics.metricValues(CoreMetric.SERVICE_CALL_DURATION)).hasOnlyOneElementSatisfying(d -> {
assertThat(d).isGreaterThanOrEqualTo(Duration.ZERO);
});
assertThat(requestMetrics.metricValues(CoreMetric.UNMARSHALLING_DURATION)).hasOnlyOneElementSatisfying(d -> {
assertThat(d).isGreaterThanOrEqualTo(Duration.ZERO);
});
}
}
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class CoreMetricsTest method setup.
@Before
public void setup() throws IOException {
client = ProtocolRestJsonClient.builder().httpClient(mockHttpClient).region(Region.US_WEST_2).credentialsProvider(mockCredentialsProvider).overrideConfiguration(c -> c.addMetricPublisher(mockPublisher).retryPolicy(b -> b.numRetries(MAX_RETRIES))).build();
AbortableInputStream content = contentStream("{}");
SdkHttpFullResponse httpResponse = SdkHttpFullResponse.builder().statusCode(200).putHeader("x-amz-request-id", REQUEST_ID).putHeader("x-amz-id-2", EXTENDED_REQUEST_ID).content(content).build();
HttpExecuteResponse mockResponse = mockExecuteResponse(httpResponse);
ExecutableHttpRequest mockExecuteRequest = mock(ExecutableHttpRequest.class);
when(mockExecuteRequest.call()).thenAnswer(invocation -> {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
return mockResponse;
});
when(mockHttpClient.prepareRequest(any(HttpExecuteRequest.class))).thenReturn(mockExecuteRequest);
when(mockCredentialsProvider.resolveCredentials()).thenAnswer(invocation -> {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
return AwsBasicCredentials.create("foo", "bar");
});
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class SyncClientMetricPublisherResolutionTest method clientWithPublishers.
private ProtocolRestJsonClient clientWithPublishers(MetricPublisher... metricPublishers) throws IOException {
ProtocolRestJsonClientBuilder builder = ProtocolRestJsonClient.builder().httpClient(mockHttpClient).region(Region.US_WEST_2).credentialsProvider(mockCredentialsProvider);
AbortableInputStream content = AbortableInputStream.create(new ByteArrayInputStream("{}".getBytes()));
SdkHttpFullResponse httpResponse = SdkHttpFullResponse.builder().statusCode(200).content(content).build();
HttpExecuteResponse mockResponse = mockExecuteResponse(httpResponse);
ExecutableHttpRequest mockExecuteRequest = mock(ExecutableHttpRequest.class);
when(mockExecuteRequest.call()).thenAnswer(invocation -> {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
return mockResponse;
});
when(mockHttpClient.prepareRequest(any(HttpExecuteRequest.class))).thenReturn(mockExecuteRequest);
when(mockCredentialsProvider.resolveCredentials()).thenAnswer(invocation -> {
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
return AwsBasicCredentials.create("foo", "bar");
});
if (metricPublishers != null) {
builder.overrideConfiguration(o -> o.metricPublishers(Arrays.asList(metricPublishers)));
}
return builder.build();
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class CombinedResponseAsyncHttpResponseHandler method prepare.
@Override
public CompletableFuture<Response<OutputT>> prepare() {
headersFuture = new CompletableFuture<>();
CompletableFuture<OutputT> preparedTransformFuture = successResponseHandler.prepare();
CompletableFuture<? extends SdkException> preparedErrorTransformFuture = errorResponseHandler == null ? null : errorResponseHandler.prepare();
return headersFuture.thenCompose(headers -> {
SdkHttpFullResponse sdkHttpFullResponse = toFullResponse(headers);
if (headers.isSuccessful()) {
return preparedTransformFuture.thenApply(r -> Response.<OutputT>builder().response(r).httpResponse(sdkHttpFullResponse).isSuccess(true).build());
}
if (preparedErrorTransformFuture != null) {
return preparedErrorTransformFuture.thenApply(e -> Response.<OutputT>builder().exception(e).httpResponse(sdkHttpFullResponse).isSuccess(false).build());
}
return CompletableFuture.completedFuture(Response.<OutputT>builder().httpResponse(sdkHttpFullResponse).isSuccess(false).build());
});
}
Aggregations