Search in sources :

Example 6 with HttpExecuteRequest

use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.

the class MetricReportingTest method prepareRequest_connectionManagerNotPooling_callableCalled_metricsReported.

@Test
public void prepareRequest_connectionManagerNotPooling_callableCalled_metricsReported() throws IOException {
    ApacheHttpClient client = newClient();
    when(mockHttpClient.getHttpClientConnectionManager()).thenReturn(mock(HttpClientConnectionManager.class));
    MetricCollector collector = MetricCollector.create("test");
    HttpExecuteRequest executeRequest = newRequest(collector);
    client.prepareRequest(executeRequest).call();
    MetricCollection collected = collector.collect();
    assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache");
    assertThat(collected.metricValues(LEASED_CONCURRENCY)).isEmpty();
    assertThat(collected.metricValues(PENDING_CONCURRENCY_ACQUIRES)).isEmpty();
    assertThat(collected.metricValues(AVAILABLE_CONCURRENCY)).isEmpty();
    assertThat(collected.metricValues(MAX_CONCURRENCY)).isEmpty();
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) Test(org.junit.Test)

Example 7 with HttpExecuteRequest

use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.

the class MetricReportingTest method newRequest.

private HttpExecuteRequest newRequest(MetricCollector collector) {
    final SdkHttpFullRequest sdkRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.HEAD).host("amazonaws.com").protocol("https").build();
    HttpExecuteRequest executeRequest = HttpExecuteRequest.builder().request(sdkRequest).metricCollector(collector).build();
    return executeRequest;
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest)

Example 8 with HttpExecuteRequest

use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.

the class MetricReportingTest method prepareRequest_callableCalled_metricsReported.

@Test
public void prepareRequest_callableCalled_metricsReported() throws IOException {
    ApacheHttpClient client = newClient();
    MetricCollector collector = MetricCollector.create("test");
    HttpExecuteRequest executeRequest = newRequest(collector);
    client.prepareRequest(executeRequest).call();
    MetricCollection collected = collector.collect();
    assertThat(collected.metricValues(HTTP_CLIENT_NAME)).containsExactly("Apache");
    assertThat(collected.metricValues(LEASED_CONCURRENCY)).containsExactly(1);
    assertThat(collected.metricValues(PENDING_CONCURRENCY_ACQUIRES)).containsExactly(2);
    assertThat(collected.metricValues(AVAILABLE_CONCURRENCY)).containsExactly(3);
    assertThat(collected.metricValues(MAX_CONCURRENCY)).containsExactly(4);
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) MetricCollection(software.amazon.awssdk.metrics.MetricCollection) MetricCollector(software.amazon.awssdk.metrics.MetricCollector) Test(org.junit.Test)

Example 9 with HttpExecuteRequest

use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.

the class SignersIntegrationTest method sign_WithoutUsingSdkClient_ThroughExecutionAttributes.

@Test
public void sign_WithoutUsingSdkClient_ThroughExecutionAttributes() throws Exception {
    Aws4Signer signer = Aws4Signer.create();
    SdkHttpFullRequest httpFullRequest = generateBasicRequest();
    // sign the request
    SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructExecutionAttributes());
    SdkHttpClient httpClient = ApacheHttpClient.builder().build();
    HttpExecuteRequest request = HttpExecuteRequest.builder().request(signedRequest).contentStreamProvider(signedRequest.contentStreamProvider().orElse(null)).build();
    HttpExecuteResponse response = httpClient.prepareRequest(request).call();
    assertEquals("Non success http status code", 200, response.httpResponse().statusCode());
    String actualResult = IoUtils.toUtf8String(response.responseBody().get());
    assertEquals(getExpectedResult(), actualResult);
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) Aws4Signer(software.amazon.awssdk.auth.signer.Aws4Signer) Test(org.junit.Test)

Example 10 with HttpExecuteRequest

use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.

the class SignersIntegrationTest method test_SignMethod_WithModeledParam_And_WithoutUsingSdkClient.

@Test
public void test_SignMethod_WithModeledParam_And_WithoutUsingSdkClient() throws Exception {
    Aws4Signer signer = Aws4Signer.create();
    SdkHttpFullRequest httpFullRequest = generateBasicRequest();
    // sign the request
    SdkHttpFullRequest signedRequest = signer.sign(httpFullRequest, constructSignerParams());
    SdkHttpClient httpClient = ApacheHttpClient.builder().build();
    HttpExecuteRequest request = HttpExecuteRequest.builder().request(signedRequest).contentStreamProvider(signedRequest.contentStreamProvider().orElse(null)).build();
    HttpExecuteResponse response = httpClient.prepareRequest(request).call();
    assertEquals("Non success http status code", 200, response.httpResponse().statusCode());
    String actualResult = IoUtils.toUtf8String(response.responseBody().get());
    assertEquals(getExpectedResult(), actualResult);
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) Aws4Signer(software.amazon.awssdk.auth.signer.Aws4Signer) Test(org.junit.Test)

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