use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class Crc32ValidationTest method adapt_InputStreamWithNoGzipOrCrc32_NotWrappedWhenAdapted.
@Test
public void adapt_InputStreamWithNoGzipOrCrc32_NotWrappedWhenAdapted() {
InputStream content = new StringInputStream("content");
SdkHttpFullResponse httpResponse = SdkHttpFullResponse.builder().statusCode(200).content(AbortableInputStream.create(content)).build();
SdkHttpFullResponse adapted = adapt(httpResponse);
InputStream in = adapted.content().get().delegate();
assertThat(in).isEqualTo(content);
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class Crc32ValidationTest method adapt_InvalidGzipContent_ThrowsException.
@Test(expected = UncheckedIOException.class)
public void adapt_InvalidGzipContent_ThrowsException() throws UnsupportedEncodingException {
InputStream content = new StringInputStream("this isn't GZIP");
SdkHttpFullResponse httpResponse = SdkHttpFullResponse.builder().statusCode(200).putHeader("Content-Encoding", "gzip").content(AbortableInputStream.create(content)).build();
SdkHttpFullResponse adapted = adapt(httpResponse);
InputStream in = adapted.content().get().delegate();
assertThat(in).isInstanceOf((GZIPInputStream.class));
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class S3MrapIntegrationTest method applyPresignedUrl.
private String applyPresignedUrl(PresignedRequest presignedRequest, String content) {
try {
HttpExecuteRequest.Builder builder = HttpExecuteRequest.builder().request(presignedRequest.httpRequest());
if (!isEmpty(content)) {
builder.contentStreamProvider(() -> new StringInputStream(content));
}
HttpExecuteRequest request = builder.build();
HttpExecuteResponse response = ApacheHttpClient.create().prepareRequest(request).call();
return response.responseBody().map(stream -> invokeSafely(() -> IoUtils.toUtf8String(stream))).orElseThrow(() -> new IOException("No input stream"));
} catch (IOException e) {
log.error(() -> "Error occurred ", e);
}
return null;
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class ProfileDisableMultiRegionProviderTest method specifiedInOverrideConfig_shouldUse.
@Test
public void specifiedInOverrideConfig_shouldUse() {
ExecutionInterceptor interceptor = Mockito.spy(AbstractExecutionInterceptor.class);
String profileFileContent = "[default]\n" + "s3_disable_multiregion_access_points = true\n";
ProfileFile profileFile = ProfileFile.builder().type(ProfileFile.Type.CONFIGURATION).content(new StringInputStream(profileFileContent)).build();
S3Client s3 = S3Client.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).overrideConfiguration(c -> c.defaultProfileFile(profileFile).defaultProfileName("default").addExecutionInterceptor(interceptor).retryPolicy(r -> r.numRetries(0))).serviceConfiguration(s -> s.useArnRegionEnabled(true)).build();
String arn = "arn:aws:s3:us-banana-46:12345567890:accesspoint:foo";
assertThatThrownBy(() -> s3.getObject(r -> r.bucket(arn).key("bar"))).isInstanceOf(SdkException.class);
ArgumentCaptor<Context.BeforeTransmission> context = ArgumentCaptor.forClass(Context.BeforeTransmission.class);
Mockito.verify(interceptor).beforeTransmission(context.capture(), any());
String host = context.getValue().httpRequest().host();
assertThat(host).contains("us-banana-46");
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-lambda-powertools-java by awslabs.
the class CloudFormationResponse method send.
/**
* Forwards a response containing a custom payload to the target resource specified by the event. The payload is
* formed from the event, context, and response data.
*
* @param event custom CF resource event. Cannot be null.
* @param context used to specify when the function and any callbacks have completed execution, or to
* access information from within the Lambda execution environment. Cannot be null.
* @param responseData response to send, e.g. a list of name-value pairs. If null, an empty success is assumed.
* @return the response object
* @throws IOException when unable to generate or send the request
* @throws CustomResourceResponseException when unable to serialize the response payload
*/
public HttpExecuteResponse send(CloudFormationCustomResourceEvent event, Context context, Response responseData) throws IOException, CustomResourceResponseException {
// no need to explicitly close in-memory stream
StringInputStream stream = responseBodyStream(event, context, responseData);
URI uri = URI.create(event.getResponseUrl());
SdkHttpRequest request = SdkHttpRequest.builder().uri(uri).method(SdkHttpMethod.PUT).headers(headers(stream.available())).build();
HttpExecuteRequest httpExecuteRequest = HttpExecuteRequest.builder().request(request).contentStreamProvider(() -> stream).build();
return client.prepareRequest(httpExecuteRequest).call();
}
Aggregations