Search in sources :

Example 21 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 22 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 = inputRequest.encodedQueryParameters().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) 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 23 with HttpRequest

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

the class S3CrtAsyncHttpClientTest method defaultRequest_shouldSetMetaRequestOptionsCorrectly.

@Test
public void defaultRequest_shouldSetMetaRequestOptionsCorrectly() {
    AsyncExecuteRequest asyncExecuteRequest = getExecuteRequestBuilder().build();
    ArgumentCaptor<S3MetaRequestOptions> s3MetaRequestOptionsArgumentCaptor = ArgumentCaptor.forClass(S3MetaRequestOptions.class);
    asyncHttpClient.execute(asyncExecuteRequest);
    verify(s3Client).makeMetaRequest(s3MetaRequestOptionsArgumentCaptor.capture());
    S3MetaRequestOptions actual = s3MetaRequestOptionsArgumentCaptor.getValue();
    assertThat(actual.getMetaRequestType()).isEqualTo(S3MetaRequestOptions.MetaRequestType.DEFAULT);
    assertThat(actual.getCredentialsProvider()).isNull();
    assertThat(actual.getEndpoint().equals(DEFAULT_ENDPOINT));
    HttpRequest httpRequest = actual.getHttpRequest();
    assertThat(httpRequest.getEncodedPath()).isEqualTo("/key");
    Map<String, String> headers = httpRequest.getHeaders().stream().collect(HashMap::new, (m, h) -> m.put(h.getName(), h.getValue()), Map::putAll);
    assertThat(headers).hasSize(4).containsEntry("Host", DEFAULT_ENDPOINT.getHost()).containsEntry("custom-header", "foobar").containsEntry("amz-sdk-invocation-id", "1234").containsEntry("Content-Length", "100");
}
Also used : HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) S3MetaRequestOptions(software.amazon.awssdk.crt.s3.S3MetaRequestOptions) HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 24 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 asyncRequest) {
    CompletableFuture<Void> executeFuture = new CompletableFuture<>();
    URI uri = asyncRequest.request().getUri();
    HttpRequest httpRequest = toCrtRequest(uri, asyncRequest);
    S3CrtResponseHandlerAdapter responseHandler = new S3CrtResponseHandlerAdapter(executeFuture, asyncRequest.responseHandler());
    S3MetaRequestOptions.MetaRequestType requestType = requestType(asyncRequest);
    S3MetaRequestOptions requestOptions = new S3MetaRequestOptions().withHttpRequest(httpRequest).withMetaRequestType(requestType).withResponseHandler(responseHandler).withEndpoint(s3NativeClientConfiguration.endpointOverride());
    try (S3MetaRequest s3MetaRequest = crtS3Client.makeMetaRequest(requestOptions)) {
        closeResourcesWhenComplete(executeFuture, s3MetaRequest, responseHandler);
    }
    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) URI(java.net.URI)

Example 25 with HttpRequest

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

the class S3CrtAsyncHttpClient method toCrtRequest.

private static HttpRequest toCrtRequest(URI uri, AsyncExecuteRequest asyncRequest) {
    SdkHttpRequest sdkRequest = asyncRequest.request();
    String method = sdkRequest.method().name();
    String encodedPath = sdkRequest.encodedPath();
    if (encodedPath == null || encodedPath.isEmpty()) {
        encodedPath = "/";
    }
    String encodedQueryString = sdkRequest.encodedQueryParameters().map(value -> "?" + value).orElse("");
    HttpHeader[] crtHeaderArray = createHttpHeaderList(uri, asyncRequest).toArray(new HttpHeader[0]);
    S3CrtRequestBodyStreamAdapter sdkToCrtRequestPublisher = new S3CrtRequestBodyStreamAdapter(asyncRequest.requestContentPublisher());
    return new HttpRequest(method, encodedPath + encodedQueryString, crtHeaderArray, sdkToCrtRequestPublisher);
}
Also used : S3ClientOptions(software.amazon.awssdk.crt.s3.S3ClientOptions) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) S3MetaRequest(software.amazon.awssdk.crt.s3.S3MetaRequest) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) Logger(software.amazon.awssdk.utils.Logger) CompletableFuture(java.util.concurrent.CompletableFuture) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) AttributeMap(software.amazon.awssdk.utils.AttributeMap) S3MetaRequestOptions(software.amazon.awssdk.crt.s3.S3MetaRequestOptions) ArrayList(java.util.ArrayList) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) OPERATION_NAME(software.amazon.awssdk.services.s3.internal.crt.S3InternalSdkHttpExecutionAttribute.OPERATION_NAME) List(java.util.List) Header(software.amazon.awssdk.http.Header) Optional(java.util.Optional) S3Client(software.amazon.awssdk.crt.s3.S3Client) URI(java.net.URI) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) SdkTestInternalApi(software.amazon.awssdk.annotations.SdkTestInternalApi) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Region(software.amazon.awssdk.regions.Region) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader)

Aggregations

HttpRequest (software.amazon.awssdk.crt.http.HttpRequest)47 HttpHeader (software.amazon.awssdk.crt.http.HttpHeader)26 Test (org.junit.Test)22 URI (java.net.URI)15 ByteBuffer (java.nio.ByteBuffer)13 HttpRequestBodyStream (software.amazon.awssdk.crt.http.HttpRequestBodyStream)13 AwsSigningConfig (software.amazon.awssdk.crt.auth.signing.AwsSigningConfig)11 CompletableFuture (java.util.concurrent.CompletableFuture)8 StaticCredentialsProvider (software.amazon.awssdk.crt.auth.credentials.StaticCredentialsProvider)8 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 ArrayList (java.util.ArrayList)6 AwsSigningResult (software.amazon.awssdk.crt.auth.signing.AwsSigningResult)6 AsyncExecuteRequest (software.amazon.awssdk.http.async.AsyncExecuteRequest)6 S3MetaRequestOptions (software.amazon.awssdk.crt.s3.S3MetaRequestOptions)5 Optional (java.util.Optional)4 S3MetaRequest (software.amazon.awssdk.crt.s3.S3MetaRequest)4 StandardCharsets (java.nio.charset.StandardCharsets)3 Arrays (java.util.Arrays)3