use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class MakeHttpRequestStageTest method testExecute_contextContainsMetricCollector_addsChildToExecuteRequest.
@Test
public void testExecute_contextContainsMetricCollector_addsChildToExecuteRequest() {
SdkHttpFullRequest sdkRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).host("mybucket.s3.us-west-2.amazonaws.com").protocol("https").build();
MetricCollector mockCollector = mock(MetricCollector.class);
MetricCollector childCollector = mock(MetricCollector.class);
when(mockCollector.createChild(any(String.class))).thenReturn(childCollector);
ExecutionContext executionContext = ExecutionContext.builder().executionAttributes(new ExecutionAttributes()).build();
RequestExecutionContext context = RequestExecutionContext.builder().originalRequest(ValidSdkObjects.sdkRequest()).executionContext(executionContext).build();
context.attemptMetricCollector(mockCollector);
context.apiCallAttemptTimeoutTracker(mock(TimeoutTracker.class));
context.apiCallTimeoutTracker(mock(TimeoutTracker.class));
try {
stage.execute(sdkRequest, context);
} catch (Exception e) {
// ignored, don't really care about successful execution of the stage in this case
} finally {
ArgumentCaptor<HttpExecuteRequest> httpRequestCaptor = ArgumentCaptor.forClass(HttpExecuteRequest.class);
verify(mockCollector).createChild(eq("HttpClient"));
verify(mockClient).prepareRequest(httpRequestCaptor.capture());
assertThat(httpRequestCaptor.getValue().metricCollector()).contains(childCollector);
}
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class AmazonHttpClientTest method testUserAgentContainsRetryModeInfo.
@Test
public void testUserAgentContainsRetryModeInfo() {
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")).option(SdkClientOption.RETRY_POLICY, RetryPolicy.forRetryMode(RetryMode.STANDARD)).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("cfg/retry-mode/standard"));
}
use of software.amazon.awssdk.http.HttpExecuteRequest 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.http.HttpExecuteRequest 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.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class S3MrapIntegrationTest method applyPresignedUrl.
private String applyPresignedUrl(PresignedRequest presignedRequest, String content) {
try {
HttpExecuteRequest.Builder builder = HttpExecuteRequest.builder().request(presignedRequest.httpRequest());
if (!isEmpty(content)) {
builder.contentStreamProvider(() -> new StringInputStream(content));
}
HttpExecuteRequest request = builder.build();
HttpExecuteResponse response = ApacheHttpClient.create().prepareRequest(request).call();
return response.responseBody().map(stream -> invokeSafely(() -> IoUtils.toUtf8String(stream))).orElseThrow(() -> new IOException("No input stream"));
} catch (IOException e) {
log.error(() -> "Error occurred ", e);
}
return null;
}
Aggregations