use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class S3PresignerIntegrationTest method execute.
private HttpExecuteResponse execute(PresignedRequest presigned, String payload) throws IOException {
SdkHttpClient httpClient = ApacheHttpClient.builder().build();
ContentStreamProvider requestPayload = payload == null ? null : () -> new StringInputStream(payload);
HttpExecuteRequest request = HttpExecuteRequest.builder().request(presigned.httpRequest()).contentStreamProvider(requestPayload).build();
return httpClient.prepareRequest(request).call();
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class ApacheMetricsTest method makeRequestWithMetrics.
private HttpExecuteResponse makeRequestWithMetrics(SdkHttpClient httpClient, MetricCollector metricCollector) throws IOException {
SdkHttpRequest httpRequest = SdkHttpFullRequest.builder().method(SdkHttpMethod.GET).protocol("http").host("localhost:" + wireMockServer.port()).build();
HttpExecuteRequest request = HttpExecuteRequest.builder().request(httpRequest).metricCollector(metricCollector).build();
return httpClient.prepareRequest(request).call();
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class ApacheHttpRequestFactoryTest method defaultHttpPortsAreNotInDefaultHostHeader.
@Test
public void defaultHttpPortsAreNotInDefaultHostHeader() {
SdkHttpRequest sdkRequest = SdkHttpRequest.builder().uri(URI.create("http://localhost:80/")).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", hostHeaders[0].getValue());
sdkRequest = SdkHttpRequest.builder().uri(URI.create("https://localhost:443/")).method(SdkHttpMethod.HEAD).build();
request = HttpExecuteRequest.builder().request(sdkRequest).build();
result = instance.create(request, requestConfig);
hostHeaders = result.getHeaders(HttpHeaders.HOST);
assertNotNull(hostHeaders);
assertEquals(1, hostHeaders.length);
assertEquals("localhost", hostHeaders[0].getValue());
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-sdk-java-v2 by aws.
the class UrlConnectionHttpClient method createAndConfigureConnection.
private HttpURLConnection createAndConfigureConnection(HttpExecuteRequest request) {
HttpURLConnection connection = connectionFactory.createConnection(request.httpRequest().getUri());
request.httpRequest().headers().forEach((key, values) -> values.forEach(value -> connection.setRequestProperty(key, value)));
invokeSafely(() -> connection.setRequestMethod(request.httpRequest().method().name()));
if (request.contentStreamProvider().isPresent()) {
connection.setDoOutput(true);
}
// Disable following redirects since it breaks SDK error handling and matches Apache.
// See: https://github.com/aws/aws-sdk-java-v2/issues/975
connection.setInstanceFollowRedirects(false);
request.httpRequest().firstMatchingHeader(CONTENT_LENGTH).map(Long::parseLong).ifPresent(connection::setFixedLengthStreamingMode);
return connection;
}
use of software.amazon.awssdk.http.HttpExecuteRequest in project aws-greengrass-nucleus by aws-greengrass.
the class GreengrassRepositoryDownloader method getDownloadSizeWithoutRetry.
private Long getDownloadSizeWithoutRetry() throws InterruptedException, PackageDownloadException, IOException {
String url = getArtifactDownloadURL(identifier, artifact.getArtifactUri().getSchemeSpecificPart());
try (SdkHttpClient client = getSdkHttpClient()) {
HttpExecuteRequest executeRequest = HttpExecuteRequest.builder().request(SdkHttpFullRequest.builder().uri(URI.create(url)).method(SdkHttpMethod.GET).build()).build();
HttpExecuteResponse executeResponse = client.prepareRequest(executeRequest).call();
int responseCode = executeResponse.httpResponse().statusCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
long length = getContentLengthLong(executeResponse.httpResponse());
if (length == -1) {
throw new PackageDownloadException(getErrorString("Failed to get download size"));
}
return length;
} else {
throw new PackageDownloadException(getErrorString("Failed to get download size. HTTP response: " + responseCode));
}
}
}
Aggregations