Search in sources :

Example 1 with HttpRequest

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

the class AwsCrt4aSigningAdapter method sign.

public SdkSigningResult sign(SdkHttpFullRequest request, AwsSigningConfig signingConfig) {
    HttpRequest crtRequest = requestConverter.requestToCrt(SigningUtils.sanitizeSdkRequestForCrtSigning(request));
    CompletableFuture<AwsSigningResult> future = AwsSigner.sign(crtRequest, signingConfig);
    try {
        AwsSigningResult signingResult = future.get();
        return requestConverter.crtResultToAws(request, signingResult);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        throw SdkClientException.create("The thread got interrupted while attempting to sign request: " + e.getMessage(), e);
    } catch (Exception e) {
        throw SdkClientException.create("Unable to sign request: " + e.getMessage(), e);
    }
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) AwsSigningResult(software.amazon.awssdk.crt.auth.signing.AwsSigningResult) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException)

Example 2 with HttpRequest

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

the class CrtHttpRequestConverterTest method request_withQueryParams_isConvertedToCrtFormat.

@Test
public void request_withQueryParams_isConvertedToCrtFormat() {
    SdkHttpFullRequest request = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).putRawQueryParameter("param1", "value1").putRawQueryParameter("param2", Arrays.asList("value2-1", "value2-2")).putHeader("Host", "demo.us-east-1.amazonaws.com").encodedPath("/path").uri(URI.create("https://demo.us-east-1.amazonaws.com")).build();
    HttpRequest crtHttpRequest = converter.requestToCrt(request);
    assertThat(crtHttpRequest.getMethod()).isEqualTo("GET");
    assertThat(crtHttpRequest.getEncodedPath()).isEqualTo("/path?param1=value1&param2=value2-1&param2=value2-2");
    assertHttpRequestSame(request, crtHttpRequest);
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.jupiter.api.Test)

Example 3 with HttpRequest

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

the class CrtHttpRequestConverterTest method request_withEmptyPath_isConvertedToCrtFormat.

@Test
public void request_withEmptyPath_isConvertedToCrtFormat() {
    SdkHttpFullRequest request = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).putHeader("Host", "demo.us-east-1.amazonaws.com").encodedPath("").uri(URI.create("https://demo.us-east-1.amazonaws.com")).build();
    HttpRequest crtHttpRequest = converter.requestToCrt(request);
    assertThat(crtHttpRequest.getEncodedPath()).isEqualTo("/");
    assertHttpRequestSame(request, crtHttpRequest);
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) Test(org.junit.jupiter.api.Test)

Example 4 with HttpRequest

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

the class CrtHttpRequestConverter method requestToCrt.

public HttpRequest requestToCrt(SdkHttpFullRequest inputRequest) {
    String method = inputRequest.method().name();
    String encodedPath = encodedPathToCrtFormat(inputRequest.encodedPath());
    String encodedQueryString = SdkHttpUtils.encodeAndFlattenQueryParameters(inputRequest.rawQueryParameters()).map(value -> "?" + value).orElse("");
    HttpHeader[] crtHeaderArray = createHttpHeaderArray(inputRequest);
    Optional<ContentStreamProvider> contentProvider = inputRequest.contentStreamProvider();
    HttpRequestBodyStream crtInputStream = null;
    if (contentProvider.isPresent()) {
        crtInputStream = new CrtHttpRequestConverter.CrtInputStream(contentProvider.get());
    }
    return new HttpRequest(method, encodedPath + encodedQueryString, crtHeaderArray, crtInputStream);
}
Also used : StringUtils(software.amazon.awssdk.utils.StringUtils) SdkHttpUtils(software.amazon.awssdk.utils.http.SdkHttpUtils) URISyntaxException(java.net.URISyntaxException) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider) IOException(java.io.IOException) Math.min(java.lang.Math.min) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) CollectionUtils.isNullOrEmpty(software.amazon.awssdk.utils.CollectionUtils.isNullOrEmpty) Map(java.util.Map) HttpRequestBodyStream(software.amazon.awssdk.crt.http.HttpRequestBodyStream) AwsSigningResult(software.amazon.awssdk.crt.auth.signing.AwsSigningResult) Optional(java.util.Optional) URI(java.net.URI) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) InputStream(java.io.InputStream) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) HttpRequestBodyStream(software.amazon.awssdk.crt.http.HttpRequestBodyStream) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider)

Example 5 with HttpRequest

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

the class S3CrtAsyncHttpClient method execute.

@Override
public CompletableFuture<Void> execute(AsyncExecuteRequest request) {
    CompletableFuture<Void> executeFuture = new CompletableFuture<>();
    HttpRequest httpRequest = toCrtRequest(request);
    S3CrtResponseHandlerAdapter responseHandler = new S3CrtResponseHandlerAdapter(executeFuture, request.responseHandler());
    S3MetaRequestOptions.MetaRequestType requestType = requestType(request);
    S3MetaRequestOptions requestOptions = new S3MetaRequestOptions().withHttpRequest(httpRequest).withMetaRequestType(requestType).withResponseHandler(responseHandler);
    try (S3MetaRequest s3MetaRequest = crtS3Client.makeMetaRequest(requestOptions)) {
        closeResourcesWhenComplete(executeFuture, s3MetaRequest);
    }
    return executeFuture;
}
Also used : SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) CompletableFuture(java.util.concurrent.CompletableFuture) S3MetaRequestOptions(software.amazon.awssdk.crt.s3.S3MetaRequestOptions) S3MetaRequest(software.amazon.awssdk.crt.s3.S3MetaRequest)

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