Search in sources :

Example 6 with AmazonSyncHttpClient

use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.

the class AmazonHttpClientTest method testUserAgentPrefixAndSuffixAreAdded.

@Test
public void testUserAgentPrefixAndSuffixAreAdded() {
    String prefix = "somePrefix";
    String suffix = "someSuffix-blah-blah";
    HttpResponseHandler<?> handler = mock(HttpResponseHandler.class);
    SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder().option(SdkAdvancedClientOption.USER_AGENT_PREFIX, prefix).option(SdkAdvancedClientOption.USER_AGENT_SUFFIX, suffix).option(SdkClientOption.SYNC_HTTP_CLIENT, sdkHttpClient).option(SdkClientOption.ENDPOINT, URI.create("http://example.com")).build();
    AmazonSyncHttpClient client = new AmazonSyncHttpClient(config);
    client.requestExecutionBuilder().request(ValidSdkObjects.sdkHttpFullRequest().build()).originalRequest(NoopTestRequest.builder().build()).executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(null)).execute(combinedSyncResponseHandler(handler, null));
    ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
    verify(sdkHttpClient).prepareRequest(httpRequestCaptor.capture());
    final String userAgent = httpRequestCaptor.getValue().httpRequest().firstMatchingHeader("User-Agent").orElseThrow(() -> new AssertionError("User-Agent header was not found"));
    Assert.assertTrue(userAgent.startsWith(prefix));
    Assert.assertTrue(userAgent.endsWith(suffix));
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) Test(org.junit.Test)

Example 7 with AmazonSyncHttpClient

use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.

the class AmazonHttpClientTest method testUserAgentContainsHttpClientInfo.

@Test
public void testUserAgentContainsHttpClientInfo() {
    HttpResponseHandler<?> handler = mock(HttpResponseHandler.class);
    SdkClientConfiguration config = HttpTestUtils.testClientConfiguration().toBuilder().option(SdkClientOption.SYNC_HTTP_CLIENT, sdkHttpClient).option(SdkClientOption.CLIENT_TYPE, ClientType.SYNC).option(SdkClientOption.ENDPOINT, URI.create("http://example.com")).build();
    AmazonSyncHttpClient client = new AmazonSyncHttpClient(config);
    client.requestExecutionBuilder().request(ValidSdkObjects.sdkHttpFullRequest().build()).originalRequest(NoopTestRequest.builder().build()).executionContext(ClientExecutionAndRequestTimerTestUtils.executionContext(null)).execute(combinedSyncResponseHandler(handler, null));
    ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
    verify(sdkHttpClient).prepareRequest(httpRequestCaptor.capture());
    final String userAgent = httpRequestCaptor.getValue().httpRequest().firstMatchingHeader("User-Agent").orElseThrow(() -> new AssertionError("User-Agent header was not found"));
    Assert.assertTrue(userAgent.contains("io/sync"));
    Assert.assertTrue(userAgent.contains("http/UNKNOWN"));
}
Also used : HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) SdkClientConfiguration(software.amazon.awssdk.core.client.config.SdkClientConfiguration) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) Test(org.junit.Test)

Example 8 with AmazonSyncHttpClient

use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.

the class ContentStreamProviderWireMockTest method closesAllCreatedInputStreamsFromProvider.

@Test
public void closesAllCreatedInputStreamsFromProvider() {
    stubFor(any(urlPathEqualTo(OPERATION)).willReturn(aResponse().withStatus(500)));
    TestContentStreamProvider provider = new TestContentStreamProvider();
    SdkHttpFullRequest request = newRequest(OPERATION).contentStreamProvider(provider).method(SdkHttpMethod.PUT).build();
    AmazonSyncHttpClient testClient = HttpTestUtils.testAmazonHttpClient();
    try {
        sendRequest(request, testClient);
        fail("Should have thrown SdkServiceException");
    } catch (SdkServiceException ignored) {
    }
    // The test client uses the default retry policy so there should be 4
    // total attempts and an equal number created streams
    assertThat(provider.getCreatedStreams().size()).isEqualTo(4);
    for (CloseTrackingInputStream is : provider.getCreatedStreams()) {
        assertThat(is.isClosed()).isTrue();
    }
}
Also used : SdkServiceException(software.amazon.awssdk.core.exception.SdkServiceException) SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) Test(org.junit.Test)

Example 9 with AmazonSyncHttpClient

use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.

the class AmazonHttpClientWireMockTest method canHandleOptionsRequest.

@Test
public void canHandleOptionsRequest() {
    SdkHttpFullRequest request = newRequest(OPERATION).method(SdkHttpMethod.OPTIONS).build();
    AmazonSyncHttpClient sut = HttpTestUtils.testAmazonHttpClient();
    sendRequest(request, sut);
    verify(optionsRequestedFor(urlPathEqualTo(OPERATION)));
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) Test(org.junit.Test)

Example 10 with AmazonSyncHttpClient

use of software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient in project aws-sdk-java-v2 by aws.

the class AmazonHttpClientSslHandshakeTimeoutTest method testSslHandshakeTimeout.

@Test(timeout = 60 * 1000)
public void testSslHandshakeTimeout() {
    AmazonSyncHttpClient httpClient = HttpTestUtils.testClientBuilder().retryPolicy(RetryPolicy.none()).httpClient(ApacheHttpClient.builder().socketTimeout(CLIENT_SOCKET_TO).build()).build();
    System.out.println("Sending request to localhost...");
    try {
        SdkHttpFullRequest request = server.configureHttpsEndpoint(SdkHttpFullRequest.builder()).method(SdkHttpMethod.GET).build();
        httpClient.requestExecutionBuilder().request(request).originalRequest(NoopTestRequest.builder().build()).executionContext(executionContext(request)).execute(combinedSyncResponseHandler(null, new NullErrorResponseHandler()));
        fail("Client-side socket read timeout is expected!");
    } catch (SdkClientException e) {
        e.printStackTrace();
        /**
         * Http client catches the SocketTimeoutException and throws a
         * ConnectTimeoutException.
         * {@link DefaultHttpClientConnectionOperator#connect(ManagedHttpClientConnection, HttpHost,
         * InetSocketAddress, int, SocketConfig, HttpContext)}
         */
        assertThat(e).hasCauseInstanceOf(IOException.class);
    }
}
Also used : SdkHttpFullRequest(software.amazon.awssdk.http.SdkHttpFullRequest) SdkClientException(software.amazon.awssdk.core.exception.SdkClientException) AmazonSyncHttpClient(software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient) IOException(java.io.IOException) NullErrorResponseHandler(software.amazon.awssdk.core.internal.http.response.NullErrorResponseHandler) Test(org.junit.Test)

Aggregations

AmazonSyncHttpClient (software.amazon.awssdk.core.internal.http.AmazonSyncHttpClient)11 Test (org.junit.Test)10 SdkHttpFullRequest (software.amazon.awssdk.http.SdkHttpFullRequest)7 SdkClientConfiguration (software.amazon.awssdk.core.client.config.SdkClientConfiguration)4 HttpExecuteRequest (software.amazon.awssdk.http.HttpExecuteRequest)3 SdkClientException (software.amazon.awssdk.core.exception.SdkClientException)2 SdkServiceException (software.amazon.awssdk.core.exception.SdkServiceException)2 IOException (java.io.IOException)1 ConnectionPoolTimeoutException (org.apache.http.conn.ConnectionPoolTimeoutException)1 EmptySdkResponseHandler (software.amazon.awssdk.core.internal.http.response.EmptySdkResponseHandler)1 NullErrorResponseHandler (software.amazon.awssdk.core.internal.http.response.NullErrorResponseHandler)1