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));
}
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"));
}
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();
}
}
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)));
}
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);
}
}
Aggregations