Search in sources :

Example 11 with SdkHttpFullResponse

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);
    });
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) Before(org.junit.Before)

Example 12 with SdkHttpFullResponse

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);
    });
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) Before(org.junit.Before)

Example 13 with SdkHttpFullResponse

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();
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Collections.singletonList(java.util.Collections.singletonList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with SdkHttpFullResponse

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);
}
Also used : SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) InterceptorContext(software.amazon.awssdk.core.interceptor.InterceptorContext)

Example 15 with SdkHttpFullResponse

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));
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) SdkHttpFullResponse(software.amazon.awssdk.http.SdkHttpFullResponse) GZIPInputStream(java.util.zip.GZIPInputStream) Crc32ChecksumValidatingInputStream(software.amazon.awssdk.core.internal.util.Crc32ChecksumValidatingInputStream) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) StringInputStream(software.amazon.awssdk.utils.StringInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

SdkHttpFullResponse (software.amazon.awssdk.http.SdkHttpFullResponse)36 Test (org.junit.jupiter.api.Test)12 Test (org.junit.Test)11 AbortableInputStream (software.amazon.awssdk.http.AbortableInputStream)10 InputStream (java.io.InputStream)6 List (java.util.List)6 ExecutableHttpRequest (software.amazon.awssdk.http.ExecutableHttpRequest)6 StringInputStream (software.amazon.awssdk.utils.StringInputStream)6 XmlElement (software.amazon.awssdk.protocols.query.unmarshall.XmlElement)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Duration (java.time.Duration)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 Before (org.junit.Before)4 SdkBytes (software.amazon.awssdk.core.SdkBytes)4 SdkPojo (software.amazon.awssdk.core.SdkPojo)4 Crc32ChecksumValidatingInputStream (software.amazon.awssdk.core.internal.util.Crc32ChecksumValidatingInputStream)4 HttpExecuteResponse (software.amazon.awssdk.http.HttpExecuteResponse)4 IOException (java.io.IOException)3 ByteBuffer (java.nio.ByteBuffer)3 Map (java.util.Map)3