use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class XmlProtocolMarshaller method finishMarshalling.
private SdkHttpFullRequest finishMarshalling(SdkPojo pojo) {
// Content may already be set if the payload is binary data.
if (hasPayloadMembers(pojo) && request.contentStreamProvider() == null && marshallerContext.xmlGenerator() != null) {
String content = marshallerContext.xmlGenerator().stringWriter().getBuffer().toString();
if (!content.isEmpty()) {
request.contentStreamProvider(() -> new StringInputStream(content));
request.putHeader("Content-Length", Integer.toString(content.getBytes(StandardCharsets.UTF_8).length));
setContentTypeHeaderIfNeeded("application/xml");
}
}
return request.build();
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class XmlDomParserTest method multipleElementsWithSameName_ParsedCorrectly.
@Test
public void multipleElementsWithSameName_ParsedCorrectly() {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<Struct>" + " <member>valOne</member>" + " <member>valTwo</member>" + "</Struct>";
XmlElement element = XmlDomParser.parse(new StringInputStream(xml));
assertThat(element.getElementsByName("member")).hasSize(2);
assertThat(element.getElementsByName("member").get(0).textContent()).isEqualTo("valOne");
assertThat(element.getElementsByName("member").get(1).textContent()).isEqualTo("valTwo");
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class RequestBodyTest method streamConstructorHasCorrectContentType.
@Test
public void streamConstructorHasCorrectContentType() {
StringInputStream inputStream = new StringInputStream("hello world");
RequestBody requestBody = RequestBody.fromInputStream(inputStream, 11);
assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM);
IoUtils.closeQuietly(inputStream, null);
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class S3PresignerIntegrationTest method putObject_PresignedHttpRequestCanBeInvokedDirectlyBySdk.
@Test
public void putObject_PresignedHttpRequestCanBeInvokedDirectlyBySdk() throws IOException {
String objectKey = generateRandomObjectKey();
S3TestUtils.addCleanupTask(S3PresignerIntegrationTest.class, () -> client.deleteObject(r -> r.bucket(testBucket).key(objectKey)));
PresignedPutObjectRequest presigned = presigner.presignPutObject(r -> r.signatureDuration(Duration.ofMinutes(5)).putObjectRequest(por -> por.bucket(testBucket).key(objectKey)));
assertThat(presigned.isBrowserExecutable()).isFalse();
// or UrlConnectionHttpClient.builder().build()
SdkHttpClient httpClient = ApacheHttpClient.builder().build();
ContentStreamProvider requestPayload = () -> new StringInputStream(testObjectContent);
HttpExecuteRequest request = HttpExecuteRequest.builder().request(presigned.httpRequest()).contentStreamProvider(requestPayload).build();
HttpExecuteResponse response = httpClient.prepareRequest(request).call();
assertThat(response.responseBody()).isPresent();
assertThat(response.httpResponse().isSuccessful()).isTrue();
response.responseBody().ifPresent(AbortableInputStream::abort);
String content = client.getObjectAsBytes(r -> r.bucket(testBucket).key(objectKey)).asUtf8String();
assertThat(content).isEqualTo(testObjectContent);
}
use of software.amazon.awssdk.utils.StringInputStream in project aws-sdk-java-v2 by aws.
the class TraceIdTest method traceIdInterceptorIsEnabled.
@Test
public void traceIdInterceptorIsEnabled() {
EnvironmentVariableHelper.run(env -> {
env.set("AWS_LAMBDA_FUNCTION_NAME", "foo");
env.set("_X_AMZN_TRACE_ID", "bar");
try (MockSyncHttpClient mockHttpClient = new MockSyncHttpClient();
ProtocolRestJsonClient client = ProtocolRestJsonClient.builder().region(Region.US_WEST_2).credentialsProvider(AnonymousCredentialsProvider.create()).httpClient(mockHttpClient).build()) {
mockHttpClient.stubNextResponse(HttpExecuteResponse.builder().response(SdkHttpResponse.builder().statusCode(200).build()).responseBody(AbortableInputStream.create(new StringInputStream("{}"))).build());
client.allTypes();
assertThat(mockHttpClient.getLastRequest().firstMatchingHeader("X-Amzn-Trace-Id")).hasValue("bar");
}
});
}
Aggregations