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 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);
}
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");
}
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;
}
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);
}
Aggregations