Search in sources :

Example 1 with HttpHeader

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

the class AwsCrt4aSigningAdapter method signTrailerHeaders.

public AwsSigningResult signTrailerHeaders(Map<String, List<String>> headerMap, byte[] previousSignature, AwsSigningConfig signingConfig) {
    List<HttpHeader> httpHeaderList = headerMap.entrySet().stream().map(entry -> new HttpHeader(entry.getKey(), String.join(",", entry.getValue()))).collect(Collectors.toList());
    // All the config remains the same as signing config except the Signature Type.
    AwsSigningConfig configCopy = signingConfig.clone();
    configCopy.setSignatureType(AwsSigningConfig.AwsSignatureType.HTTP_REQUEST_TRAILING_HEADERS);
    CompletableFuture<AwsSigningResult> future = AwsSigner.sign(httpHeaderList, previousSignature, configCopy);
    try {
        return future.get();
    } 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 : CompletableFuture(java.util.concurrent.CompletableFuture) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) Collectors(java.util.stream.Collectors) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) AwsSigner(software.amazon.awssdk.crt.auth.signing.AwsSigner) List(java.util.List) AwsSigningConfig(software.amazon.awssdk.crt.auth.signing.AwsSigningConfig) Map(java.util.Map) HttpRequestBodyStream(software.amazon.awssdk.crt.http.HttpRequestBodyStream) AwsSigningResult(software.amazon.awssdk.crt.auth.signing.AwsSigningResult) SdkInternalApi(software.amazon.awssdk.annotations.SdkInternalApi) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) AwsSigningConfig(software.amazon.awssdk.crt.auth.signing.AwsSigningConfig) AwsSigningResult(software.amazon.awssdk.crt.auth.signing.AwsSigningResult) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException)

Example 2 with HttpHeader

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

the class CrtHttpRequestConverter method createHttpHeaderArray.

private HttpHeader[] createHttpHeaderArray(SdkHttpFullRequest request) {
    List<HttpHeader> crtHeaderList = new ArrayList<>(request.headers().size() + 2);
    // Set Host Header if needed
    if (isNullOrEmpty(request.headers().get(HOST_HEADER))) {
        crtHeaderList.add(new HttpHeader(HOST_HEADER, request.host()));
    }
    // Add the rest of the Headers
    for (Map.Entry<String, List<String>> headerList : request.headers().entrySet()) {
        for (String val : headerList.getValue()) {
            HttpHeader h = new HttpHeader(headerList.getKey(), val);
            crtHeaderList.add(h);
        }
    }
    return crtHeaderList.toArray(new HttpHeader[0]);
}
Also used : HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 3 with HttpHeader

use of software.amazon.awssdk.crt.http.HttpHeader 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 4 with HttpHeader

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

the class S3CrtAsyncHttpClient method createHttpHeaderList.

private static List<HttpHeader> createHttpHeaderList(URI uri, AsyncExecuteRequest asyncRequest) {
    SdkHttpRequest sdkRequest = asyncRequest.request();
    List<HttpHeader> crtHeaderList = new ArrayList<>();
    // Set Host Header if needed
    if (isNullOrEmpty(sdkRequest.headers().get(Header.HOST))) {
        crtHeaderList.add(new HttpHeader(Header.HOST, uri.getHost()));
    }
    // Set Content-Length if needed
    Optional<Long> contentLength = asyncRequest.requestContentPublisher().contentLength();
    if (isNullOrEmpty(sdkRequest.headers().get(Header.CONTENT_LENGTH)) && contentLength.isPresent()) {
        crtHeaderList.add(new HttpHeader(Header.CONTENT_LENGTH, Long.toString(contentLength.get())));
    }
    // Add the rest of the Headers
    sdkRequest.headers().forEach((key, value) -> value.stream().map(val -> new HttpHeader(key, val)).forEach(crtHeaderList::add));
    return crtHeaderList;
}
Also used : SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) HttpHeader(software.amazon.awssdk.crt.http.HttpHeader) ArrayList(java.util.ArrayList)

Example 5 with HttpHeader

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

the class S3CrtAsyncHttpClient method toCrtRequest.

private static HttpRequest toCrtRequest(AsyncExecuteRequest asyncRequest) {
    URI uri = asyncRequest.request().getUri();
    SdkHttpRequest sdkRequest = asyncRequest.request();
    String method = sdkRequest.method().name();
    String encodedPath = sdkRequest.encodedPath();
    if (encodedPath == null || encodedPath.isEmpty()) {
        encodedPath = "/";
    }
    String encodedQueryString = SdkHttpUtils.encodeAndFlattenQueryParameters(sdkRequest.rawQueryParameters()).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) SdkHttpUtils(software.amazon.awssdk.utils.http.SdkHttpUtils) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) S3MetaRequest(software.amazon.awssdk.crt.s3.S3MetaRequest) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) CompletableFuture(java.util.concurrent.CompletableFuture) HttpRequest(software.amazon.awssdk.crt.http.HttpRequest) AttributeMap(software.amazon.awssdk.utils.AttributeMap) OPERATION_NAME(software.amazon.awssdk.transfer.s3.internal.S3InternalSdkHttpExecutionAttribute.OPERATION_NAME) S3MetaRequestOptions(software.amazon.awssdk.crt.s3.S3MetaRequestOptions) ArrayList(java.util.ArrayList) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) List(java.util.List) Header(software.amazon.awssdk.http.Header) CollectionUtils.isNullOrEmpty(software.amazon.awssdk.utils.CollectionUtils.isNullOrEmpty) 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) URI(java.net.URI)

Aggregations

HttpHeader (software.amazon.awssdk.crt.http.HttpHeader)35 HttpRequest (software.amazon.awssdk.crt.http.HttpRequest)25 URI (java.net.URI)12 ByteBuffer (java.nio.ByteBuffer)11 Test (org.junit.Test)11 HttpRequestBodyStream (software.amazon.awssdk.crt.http.HttpRequestBodyStream)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 CompletableFuture (java.util.concurrent.CompletableFuture)6 SdkInternalApi (software.amazon.awssdk.annotations.SdkInternalApi)5 String (java.lang.String)4 Optional (java.util.Optional)4 AwsSigningResult (software.amazon.awssdk.crt.auth.signing.AwsSigningResult)4 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)4 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)4 CollectionUtils.isNullOrEmpty (software.amazon.awssdk.utils.CollectionUtils.isNullOrEmpty)4 SdkHttpUtils (software.amazon.awssdk.utils.http.SdkHttpUtils)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3