use of software.amazon.awssdk.http.ContentStreamProvider in project aws-sdk-java-v2 by aws.
the class DefaultAwsCrtS3V4aSigner method enablePayloadSigning.
private SdkHttpFullRequest enablePayloadSigning(SdkSigningResult signingResult, AwsSigningConfig chunkConfig, SignerChecksumParams signerChecksumParams) {
SdkHttpFullRequest signedRequest = signingResult.getSignedRequest();
byte[] signature = signingResult.getSignature();
SdkHttpFullRequest.Builder mutableSignedRequest = signedRequest.toBuilder();
ContentStreamProvider streamProvider = mutableSignedRequest.contentStreamProvider();
AwsS3V4aChunkSigner chunkSigner = new AwsS3V4aChunkSigner(signerAdapter, chunkConfig);
String checksumHeader = signerChecksumParams != null ? signerChecksumParams.checksumHeaderName() : null;
SdkChecksum sdkChecksum = signerChecksumParams != null ? SdkChecksum.forAlgorithm(signerChecksumParams.algorithm()) : null;
mutableSignedRequest.contentStreamProvider(() -> AwsSignedChunkedEncodingInputStream.builder().inputStream(streamProvider.newStream()).awsChunkSigner(chunkSigner).checksumHeaderForTrailer(checksumHeader).sdkChecksum(sdkChecksum).headerSignature(new String(signature, StandardCharsets.UTF_8)).awsChunkedEncodingConfig(AwsChunkedEncodingConfig.create()).build());
return mutableSignedRequest.build();
}
use of software.amazon.awssdk.http.ContentStreamProvider in project aws-sdk-java-v2 by aws.
the class QueryParametersToBodyInterceptorTest method postWithContentIsUnaltered.
@Test
public void postWithContentIsUnaltered() throws Exception {
byte[] contentBytes = "hello".getBytes(StandardCharsets.UTF_8);
ContentStreamProvider contentProvider = () -> new ByteArrayInputStream(contentBytes);
SdkHttpFullRequest request = requestBuilder.contentStreamProvider(contentProvider).build();
SdkHttpFullRequest output = (SdkHttpFullRequest) interceptor.modifyHttpRequest(new HttpRequestOnlyContext(request, null), executionAttributes);
assertThat(output.rawQueryParameters()).hasSize(1);
assertThat(output.headers()).hasSize(0);
assertThat(IoUtils.toByteArray(output.contentStreamProvider().get().newStream())).isEqualTo(contentBytes);
}
use of software.amazon.awssdk.http.ContentStreamProvider in project aws-sdk-java-v2 by aws.
the class DefaultS3Presigner method marshalRequestAndUpdateContext.
/**
* Marshal the request and update the execution context with the result.
*/
private <T> void marshalRequestAndUpdateContext(ExecutionContext execCtx, Class<T> requestType, Function<T, SdkHttpFullRequest> requestMarshaller) {
T sdkRequest = Validate.isInstanceOf(requestType, execCtx.interceptorContext().request(), "Interceptor generated unsupported type (%s) when %s was expected.", execCtx.interceptorContext().request().getClass(), requestType);
SdkHttpFullRequest marshalledRequest = requestMarshaller.apply(sdkRequest);
// TODO: The core SDK doesn't put the request body into the interceptor context. That should be fixed.
Optional<RequestBody> requestBody = marshalledRequest.contentStreamProvider().map(ContentStreamProvider::newStream).map(is -> invokeSafely(() -> IoUtils.toByteArray(is))).map(RequestBody::fromBytes);
execCtx.interceptorContext(execCtx.interceptorContext().copy(r -> r.httpRequest(marshalledRequest).requestBody(requestBody.orElse(null))));
}
Aggregations