Search in sources :

Example 1 with HttpExecuteRequest

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);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BeforeClass(org.junit.BeforeClass) ApacheHttpClient(software.amazon.awssdk.http.apache.ApacheHttpClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CreateMultipartUploadResponse(software.amazon.awssdk.services.s3.model.CreateMultipartUploadResponse) SdkBytes(software.amazon.awssdk.core.SdkBytes) PresignedAbortMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedAbortMultipartUploadRequest) RequestPayer(software.amazon.awssdk.services.s3.model.RequestPayer) S3Presigner(software.amazon.awssdk.services.s3.presigner.S3Presigner) Duration(java.time.Duration) After(org.junit.After) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) Before(org.junit.Before) UploadPartRequest(software.amazon.awssdk.services.s3.model.UploadPartRequest) AfterClass(org.junit.AfterClass) MultipartUpload(software.amazon.awssdk.services.s3.model.MultipartUpload) PresignedGetObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider) PresignedUploadPartRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedUploadPartRequest) IOException(java.io.IOException) Test(org.junit.Test) PresignedRequest(software.amazon.awssdk.awscore.presigner.PresignedRequest) UUID(java.util.UUID) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) CompleteMultipartUploadRequest(software.amazon.awssdk.services.s3.model.CompleteMultipartUploadRequest) PresignedCompleteMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedCompleteMultipartUploadRequest) S3TestUtils(software.amazon.awssdk.services.s3.utils.S3TestUtils) Consumer(java.util.function.Consumer) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) StringInputStream(software.amazon.awssdk.utils.StringInputStream) PresignedCreateMultipartUploadRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedCreateMultipartUploadRequest) Optional(java.util.Optional) RequestBody(software.amazon.awssdk.core.sync.RequestBody) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) CreateMultipartUploadRequest(software.amazon.awssdk.services.s3.model.CreateMultipartUploadRequest) AbortMultipartUploadRequest(software.amazon.awssdk.services.s3.model.AbortMultipartUploadRequest) IoUtils(software.amazon.awssdk.utils.IoUtils) InputStream(java.io.InputStream) HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) UploadPartResponse(software.amazon.awssdk.services.s3.model.UploadPartResponse) HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) StringInputStream(software.amazon.awssdk.utils.StringInputStream) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) PresignedPutObjectRequest(software.amazon.awssdk.services.s3.presigner.model.PresignedPutObjectRequest) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider) Test(org.junit.Test)

Example 2 with HttpExecuteRequest

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"));
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) InputStreamReader(java.io.InputStreamReader) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) StringInputStream(software.amazon.awssdk.utils.StringInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader)

Example 3 with HttpExecuteRequest

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();
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest)

Example 4 with HttpExecuteRequest

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());
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Header(org.apache.http.Header) Test(org.junit.jupiter.api.Test)

Example 5 with HttpExecuteRequest

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();
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest)

Aggregations

HttpExecuteRequest (software.amazon.awssdk.http.HttpExecuteRequest)26 HttpExecuteResponse (software.amazon.awssdk.http.HttpExecuteResponse)11 SdkHttpClient (software.amazon.awssdk.http.SdkHttpClient)11 Test (org.junit.Test)10 IOException (java.io.IOException)8 InputStream (java.io.InputStream)8 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)7 StringInputStream (software.amazon.awssdk.utils.StringInputStream)7 AbortableInputStream (software.amazon.awssdk.http.AbortableInputStream)5 Duration (java.time.Duration)4 Optional (java.util.Optional)4 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)4 IoUtils (software.amazon.awssdk.utils.IoUtils)4 HttpURLConnection (java.net.HttpURLConnection)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)3 AmazonSyncHttpClient (software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient)3 ContentStreamProvider (software.amazon.awssdk.http.ContentStreamProvider)3 MetricCollector (software.amazon.awssdk.metrics.MetricCollector)3 PackageDownloadException (com.aws.greengrass.componentmanager.exceptions.PackageDownloadException)2