use of software.amazon.awssdk.http.HttpExecuteRequest 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.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class DocumentTypeTest method getSyncRequestBody.
private String getSyncRequestBody() {
ArgumentCaptor<HttpExecuteRequest> captor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
Mockito.verify(httpClient).prepareRequest(captor.capture());
InputStream inputStream = captor.getValue().contentStreamProvider().get().newStream();
return new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class ApacheHttpRequestFactoryTest method sanitizedUri.
private String sanitizedUri(String path) {
SdkHttpRequest sdkRequest = SdkHttpRequest.builder().uri(URI.create("http://localhost:80")).encodedPath("/" + path).method(SdkHttpMethod.HEAD).build();
HttpExecuteRequest request = HttpExecuteRequest.builder().request(sdkRequest).build();
return instance.create(request, requestConfig).getURI().toString();
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class ApacheHttpRequestFactoryTest method ceateSetsHostHeaderByDefault.
@Test
public void ceateSetsHostHeaderByDefault() {
SdkHttpRequest sdkRequest = SdkHttpRequest.builder().uri(URI.create("http://localhost:12345/")).method(SdkHttpMethod.HEAD).build();
HttpExecuteRequest request = HttpExecuteRequest.builder().request(sdkRequest).build();
HttpRequestBase result = instance.create(request, requestConfig);
Header[] hostHeaders = result.getHeaders(HttpHeaders.HOST);
assertNotNull(hostHeaders);
assertEquals(1, hostHeaders.length);
assertEquals("localhost:12345", hostHeaders[0].getValue());
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class ApacheClientTlsAuthTest method makeRequestWithHttpClient.
private HttpExecuteResponse makeRequestWithHttpClient(SdkHttpClient httpClient) throws IOException {
SdkHttpRequest httpRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).protocol("https").host("localhost:" + wireMockServer.httpsPort()).build();
HttpExecuteRequest request = HttpExecuteRequest.builder().request(httpRequest).build();
return httpClient.prepareRequest(request).call();
}
Aggregations