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);
}
}
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¶m2=value2-1¶m2=value2-2");
assertHttpRequestSame(request, crtHttpRequest);
}
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);
}
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);
}
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;
}
Aggregations