use of software.amazon.awssdk.crt.http.HttpRequest in project aws-sdk-java-v2 by aws.
the class CrtHttpRequestConverterTest method request_withHeaders_isConvertedToCrtFormat.
@Test
public void request_withHeaders_isConvertedToCrtFormat() {
String data = "data";
SdkHttpFullRequest request = SdkHttpFullRequest.builder().method(SdkHttpMethod.POST).contentStreamProvider(() -> new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))).putHeader("x-amz-archive-description", "test test").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.getMethod()).isEqualTo("POST");
assertThat(crtHttpRequest.getEncodedPath()).isEqualTo("/");
List<HttpHeader> headers = crtHttpRequest.getHeaders();
HttpHeader[] headersAsArray = crtHttpRequest.getHeadersAsArray();
assertThat(headers.size()).isEqualTo(2);
assertThat(headersAsArray.length).isEqualTo(2);
assertThat(headers.get(0).getName()).isEqualTo("Host");
assertThat(headers.get(0).getValue()).isEqualTo("demo.us-east-1.amazonaws.com");
assertThat(headersAsArray[1].getName()).isEqualTo("x-amz-archive-description");
assertThat(headersAsArray[1].getValue()).isEqualTo("test test");
assertStream(data, crtHttpRequest.getBodyStream());
assertHttpRequestSame(request, crtHttpRequest);
}
use of software.amazon.awssdk.crt.http.HttpRequest in project aws-sdk-java-v2 by aws.
the class SignerTestUtils method verifyEcdsaSignature.
public static boolean verifyEcdsaSignature(SdkHttpFullRequest request, String expectedCanonicalRequest, AwsSigningConfig signingConfig, String signatureValue) {
CrtHttpRequestConverter requestConverter = new CrtHttpRequestConverter();
HttpRequest crtRequest = requestConverter.requestToCrt(SigningUtils.sanitizeSdkRequestForCrtSigning(request));
return AwsSigningUtils.verifySigv4aEcdsaSignature(crtRequest, expectedCanonicalRequest, signingConfig, signatureValue.getBytes(), TEST_VERIFICATION_PUB_X, TEST_VERIFICATION_PUB_Y);
}
use of software.amazon.awssdk.crt.http.HttpRequest in project aws-sdk-java-v2 by aws.
the class AwsCrt4aSigningAdapter method signRequest.
public SdkHttpFullRequest signRequest(SdkHttpFullRequest request, AwsSigningConfig signingConfig) {
HttpRequest crtRequest = requestConverter.requestToCrt(SigningUtils.sanitizeSdkRequestForCrtSigning(request));
CompletableFuture<HttpRequest> future = AwsSigner.signRequest(crtRequest, signingConfig);
try {
HttpRequest signedRequest = future.get();
return requestConverter.crtRequestToHttp(request, signedRequest);
} 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 CrtRequestExecutor method toCrtRequest.
private static HttpRequest toCrtRequest(AsyncExecuteRequest asyncRequest, AwsCrtAsyncHttpStreamAdapter crtToSdkAdapter) {
URI uri = asyncRequest.request().getUri();
SdkHttpRequest sdkRequest = asyncRequest.request();
String method = sdkRequest.method().name();
String encodedPath = sdkRequest.encodedPath();
if (encodedPath == null || encodedPath.length() == 0) {
encodedPath = "/";
}
String encodedQueryString = sdkRequest.encodedQueryParameters().map(value -> "?" + value).orElse("");
HttpHeader[] crtHeaderArray = asArray(createHttpHeaderList(uri, asyncRequest));
return new HttpRequest(method, encodedPath + encodedQueryString, crtHeaderArray, crtToSdkAdapter);
}
use of software.amazon.awssdk.crt.http.HttpRequest in project aws-sdk-java-v2 by aws.
the class CrtRequestExecutor method execute.
public CompletableFuture<Void> execute(CrtRequestContext executionContext) {
CompletableFuture<Void> requestFuture = createExecutionFuture(executionContext.sdkRequest());
// When a Connection is ready from the Connection Pool, schedule the Request on the connection
CompletableFuture<HttpClientConnection> httpClientConnectionCompletableFuture = executionContext.crtConnPool().acquireConnection();
httpClientConnectionCompletableFuture.whenComplete((crtConn, throwable) -> {
AsyncExecuteRequest asyncRequest = executionContext.sdkRequest();
// If we didn't get a connection for some reason, fail the request
if (throwable != null) {
handleFailure(new IOException("An exception occurred when acquiring connection", throwable), requestFuture, asyncRequest.responseHandler());
return;
}
AwsCrtAsyncHttpStreamAdapter crtToSdkAdapter = new AwsCrtAsyncHttpStreamAdapter(crtConn, requestFuture, asyncRequest, executionContext.readBufferSize());
HttpRequest crtRequest = toCrtRequest(asyncRequest, crtToSdkAdapter);
// Submit the Request on this Connection
invokeSafely(() -> {
try {
crtConn.makeRequest(crtRequest, crtToSdkAdapter).activate();
} catch (IllegalStateException | CrtRuntimeException e) {
log.debug(() -> "An exception occurred when making the request", e);
handleFailure(new IOException("An exception occurred when making the request", e), requestFuture, asyncRequest.responseHandler());
}
});
});
return requestFuture;
}
Aggregations