Search in sources :

Example 31 with HttpRequest

use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.

the class SigningTest method createSimpleRequest.

private HttpRequest createSimpleRequest(String endpoint, String method, String path, String body) throws Exception {
    URI uri = new URI(endpoint);
    HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()), new HttpHeader("Content-Length", Integer.toString(body.getBytes(StandardCharsets.UTF_8).length)) };
    return new HttpRequest(method, path, requestHeaders, makeBodyStreamFromString(body));
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) URI(java.net.URI)

Example 32 with HttpRequest

use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.

the class SigningTest method createChunkedTrailerTestRequest.

private HttpRequest createChunkedTrailerTestRequest() throws Exception {
    URI uri = new URI("https://s3.amazonaws.com/examplebucket/chunkObject.txt");
    HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()), new HttpHeader("x-amz-storage-class", "REDUCED_REDUNDANCY"), new HttpHeader("Content-Encoding", "aws-chunked"), new HttpHeader("x-amz-decoded-content-length", "66560"), new HttpHeader("Content-Length", "66824"), new HttpHeader("x-amz-trailer", "first,second,third") };
    return new HttpRequest("PUT", uri.getPath(), requestHeaders, null);
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) URI(java.net.URI)

Example 33 with HttpRequest

use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.

the class SigningTest method createBadBodyStreamRequest.

private HttpRequest createBadBodyStreamRequest(String method, String path) throws Exception {
    HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Something", "else") };
    HttpRequestBodyStream badBodyStream = new HttpRequestBodyStream() {

        @Override
        public boolean sendRequestBody(ByteBuffer bodyBytesOut) {
            throw new RuntimeException("Doh");
        }

        @Override
        public boolean resetPosition() {
            return true;
        }
    };
    return new HttpRequest(method, path, requestHeaders, badBodyStream);
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) HttpRequestBodyStream(software.amazon.awssdk.crt.http.HttpRequestBodyStream) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) ByteBuffer(java.nio.ByteBuffer)

Example 34 with HttpRequest

use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.

the class S3NativeClientTest method customQueryParametersTestCase.

/*
     * Runs the given test lambda for custom query parameters, passing it the
     * appropriate arguments, then validating the output.
     */
public void customQueryParametersTestCase(CustomQueryParametersTestLambda customQueryParametersTestLambda, String key, String customQueryParameters) {
    final S3Client mockInternalClient = mock(S3Client.class);
    final S3MetaRequest request = new S3MetaRequest();
    when(mockInternalClient.makeMetaRequest(any(S3MetaRequestOptions.class))).thenReturn(request);
    final S3NativeClient nativeClient = new S3NativeClient(REGION, mockInternalClient);
    customQueryParametersTestLambda.run(nativeClient, key, customQueryParameters);
    ArgumentCaptor<S3MetaRequestOptions> optionsArgument = ArgumentCaptor.forClass(S3MetaRequestOptions.class);
    verify(mockInternalClient).makeMetaRequest(optionsArgument.capture());
    List<S3MetaRequestOptions> optionsList = optionsArgument.getAllValues();
    assertEquals(optionsList.size(), 1);
    S3MetaRequestOptions options = optionsList.get(0);
    HttpRequest httpRequest = options.getHttpRequest();
    if (customQueryParameters == null || customQueryParameters.trim().equals("")) {
        assertTrue(httpRequest.getEncodedPath().equals("/" + key));
    } else {
        assertTrue(httpRequest.getEncodedPath().equals("/" + key + "?" + customQueryParameters));
    }
    reset(mockInternalClient);
    request.close();
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest)

Example 35 with HttpRequest

use of software.amazon.awssdk.crt.http.HttpRequest in project aws-crt-java by awslabs.

the class HttpRequestResponseTest method testHttpRequestUnActivated.

@Test
public void testHttpRequestUnActivated() throws Exception {
    skipIfNetworkUnavailable();
    URI uri = new URI("https://httpbin.org");
    HttpHeader[] requestHeaders = new HttpHeader[] { new HttpHeader("Host", uri.getHost()) };
    HttpRequest request = new HttpRequest("GET", "/get", requestHeaders, null);
    CompletableFuture<Void> shutdownComplete = null;
    try (HttpClientConnectionManager connPool = createConnectionPoolManager(uri)) {
        shutdownComplete = connPool.getShutdownCompleteFuture();
        try (HttpClientConnection conn = connPool.acquireConnection().get(60, TimeUnit.SECONDS)) {
            HttpStreamResponseHandler streamHandler = new HttpStreamResponseHandler() {

                @Override
                public void onResponseHeaders(HttpStream stream, int responseStatusCode, int blockType, HttpHeader[] nextHeaders) {
                // do nothing
                }

                @Override
                public void onResponseHeadersDone(HttpStream stream, int blockType) {
                // do nothing
                }

                @Override
                public int onResponseBody(HttpStream stream, byte[] bodyBytesIn) {
                    // do nothing
                    return bodyBytesIn.length;
                }

                @Override
                public void onResponseComplete(HttpStream stream, int errorCode) {
                // do nothing.
                }
            };
            HttpStream stream = conn.makeRequest(request, streamHandler);
            stream.close();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (shutdownComplete != null) {
        shutdownComplete.get();
    }
    CrtResource.waitForNoResources();
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) HttpClientConnection(software.amazon.awssdk.crt.http.HttpClientConnection) HttpStreamResponseHandler(software.amazon.awssdk.crt.http.HttpStreamResponseHandler) HttpClientConnectionManager(software.amazon.awssdk.crt.http.HttpClientConnectionManager) URI(java.net.URI) HttpStream(software.amazon.awssdk.crt.http.HttpStream) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Test(org.junit.Test)

Aggregations

HttpRequest (software.amazon.awssdk.crt.http.HttpRequest)43 HttpHeader (software.amazon.awssdk.crt.http.HttpHeader)25 Test (org.junit.Test)21 URI (java.net.URI)13 ByteBuffer (java.nio.ByteBuffer)13 HttpRequestBodyStream (software.amazon.awssdk.crt.http.HttpRequestBodyStream)13 AwsSigningConfig (software.amazon.awssdk.crt.auth.signing.AwsSigningConfig)10 StaticCredentialsProvider (software.amazon.awssdk.crt.auth.credentials.StaticCredentialsProvider)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 List (java.util.List)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 AwsSigningResult (software.amazon.awssdk.crt.auth.signing.AwsSigningResult)6 ArrayList (java.util.ArrayList)5 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)5 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 StandardCharsets (java.nio.charset.StandardCharsets)3 Arrays (java.util.Arrays)3 Optional (java.util.Optional)3 HttpClientConnection (software.amazon.awssdk.crt.http.HttpClientConnection)3