use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class HttpChecksumRequiredTest method setup.
@Before
public void setup() throws IOException {
httpClient = Mockito.mock(SdkHttpClient.class);
httpAsyncClient = Mockito.mock(SdkAsyncHttpClient.class);
jsonClient = initializeSync(ProtocolRestJsonClient.builder()).build();
jsonAsyncClient = initializeAsync(ProtocolRestJsonAsyncClient.builder()).build();
xmlClient = initializeSync(ProtocolRestXmlClient.builder()).build();
xmlAsyncClient = initializeAsync(ProtocolRestXmlAsyncClient.builder()).build();
SdkHttpFullResponse successfulHttpResponse = SdkHttpResponse.builder().statusCode(200).putHeader("Content-Length", "0").build();
ExecutableHttpRequest request = Mockito.mock(ExecutableHttpRequest.class);
Mockito.when(request.call()).thenReturn(HttpExecuteResponse.builder().response(successfulHttpResponse).build());
Mockito.when(httpClient.prepareRequest(any())).thenReturn(request);
Mockito.when(httpAsyncClient.execute(any())).thenAnswer(invocation -> {
AsyncExecuteRequest asyncExecuteRequest = invocation.getArgument(0, AsyncExecuteRequest.class);
asyncExecuteRequest.responseHandler().onHeaders(successfulHttpResponse);
asyncExecuteRequest.responseHandler().onStream(Flowable.empty());
return CompletableFuture.completedFuture(null);
});
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class HttpChecksumInHeaderTest method setup.
@Before
public void setup() throws IOException {
httpClient = Mockito.mock(SdkHttpClient.class);
httpAsyncClient = Mockito.mock(SdkAsyncHttpClient.class);
jsonClient = initializeSync(ProtocolRestJsonClient.builder()).build();
jsonAsyncClient = initializeAsync(ProtocolRestJsonAsyncClient.builder()).build();
xmlClient = initializeSync(ProtocolRestXmlClient.builder()).build();
xmlAsyncClient = initializeAsync(ProtocolRestXmlAsyncClient.builder()).build();
SdkHttpFullResponse successfulHttpResponse = SdkHttpResponse.builder().statusCode(200).putHeader("Content-Length", "0").build();
ExecutableHttpRequest request = Mockito.mock(ExecutableHttpRequest.class);
Mockito.when(request.call()).thenReturn(HttpExecuteResponse.builder().response(successfulHttpResponse).build());
Mockito.when(httpClient.prepareRequest(any())).thenReturn(request);
Mockito.when(httpAsyncClient.execute(any())).thenAnswer(invocation -> {
AsyncExecuteRequest asyncExecuteRequest = invocation.getArgument(0, AsyncExecuteRequest.class);
asyncExecuteRequest.responseHandler().onHeaders(successfulHttpResponse);
asyncExecuteRequest.responseHandler().onStream(Flowable.empty());
return CompletableFuture.completedFuture(null);
});
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class EventStreamAsyncResponseTransformer method adaptMessageToResponse.
/**
* Transforms an event stream message into a {@link SdkHttpFullResponse} so we can reuse our existing generated unmarshallers.
*
* @param message Message to transform.
*/
private SdkHttpFullResponse adaptMessageToResponse(Message message, boolean isException) {
Map<String, List<String>> headers = message.getHeaders().entrySet().stream().collect(HashMap::new, (m, e) -> m.put(e.getKey(), singletonList(e.getValue().getString())), Map::putAll);
if (requestId != null) {
headers.put(X_AMZN_REQUEST_ID_HEADER, singletonList(requestId));
}
if (extendedRequestId != null) {
headers.put(X_AMZ_ID_2_HEADER, singletonList(extendedRequestId));
}
SdkHttpFullResponse.Builder builder = SdkHttpFullResponse.builder().content(AbortableInputStream.create(new ByteArrayInputStream(message.getPayload()))).headers(headers);
if (!isException) {
builder.statusCode(200);
}
return builder.build();
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class AfterTransmissionExecutionInterceptorsStage method execute.
@Override
public Pair<SdkHttpFullRequest, SdkHttpFullResponse> execute(Pair<SdkHttpFullRequest, SdkHttpFullResponse> input, RequestExecutionContext context) throws Exception {
InterruptMonitor.checkInterrupted();
// Update interceptor context
InterceptorContext interceptorContext = context.executionContext().interceptorContext().copy(b -> b.httpResponse(input.right()).responseBody(input.right().content().orElse(null)));
// interceptors.afterTransmission
context.interceptorChain().afterTransmission(interceptorContext, context.executionAttributes());
// interceptors.modifyHttpResponse
interceptorContext = context.interceptorChain().modifyHttpResponse(interceptorContext, context.executionAttributes());
// Store updated context
context.executionContext().interceptorContext(interceptorContext);
InterruptMonitor.checkInterrupted((SdkHttpFullResponse) interceptorContext.httpResponse());
SdkHttpFullResponse response = (SdkHttpFullResponse) interceptorContext.httpResponse();
if (interceptorContext.responseBody().isPresent()) {
response = response.toBuilder().content(AbortableInputStream.create(interceptorContext.responseBody().get())).build();
}
return Pair.of(input.left(), response);
}
use of software.amazon.awssdk.http.SdkHttpFullResponse in project aws-sdk-java-v2 by aws.
the class Crc32ValidationTest method adapt_CalculateCrcFromCompressed_WrapsWithCrc32ThenGzip.
@Test
public void adapt_CalculateCrcFromCompressed_WrapsWithCrc32ThenGzip() throws IOException {
try (InputStream content = getClass().getResourceAsStream("/resources/compressed_json_body.gz")) {
SdkHttpFullResponse httpResponse = SdkHttpFullResponse.builder().statusCode(200).putHeader("Content-Encoding", "gzip").putHeader("x-amz-crc32", "1234").content(AbortableInputStream.create(content)).build();
SdkHttpFullResponse adapted = Crc32Validation.validate(true, httpResponse);
InputStream in = adapted.content().get().delegate();
assertThat(in).isInstanceOf((GZIPInputStream.class));
}
}
Aggregations