Search in sources :

Example 1 with CONTENT_LENGTH

use of software.amazon.awssdk.http.Header.CONTENT_LENGTH 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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) X509Certificate(java.security.cert.X509Certificate) SSLContext(javax.net.ssl.SSLContext) SdkPublicApi(software.amazon.awssdk.annotations.SdkPublicApi) TrustManager(javax.net.ssl.TrustManager) HttpStatusFamily(software.amazon.awssdk.http.HttpStatusFamily) TlsKeyManagersProvider(software.amazon.awssdk.http.TlsKeyManagersProvider) AttributeMap(software.amazon.awssdk.utils.AttributeMap) Supplier(java.util.function.Supplier) FunctionalUtils.invokeSafely(software.amazon.awssdk.utils.FunctionalUtils.invokeSafely) SSLSession(javax.net.ssl.SSLSession) NumericUtils.saturatedCast(software.amazon.awssdk.utils.NumericUtils.saturatedCast) Duration(java.time.Duration) Map(java.util.Map) URI(java.net.URI) HostnameVerifier(javax.net.ssl.HostnameVerifier) TlsTrustManagersProvider(software.amazon.awssdk.http.TlsTrustManagersProvider) OutputStream(java.io.OutputStream) CONTENT_LENGTH(software.amazon.awssdk.http.Header.CONTENT_LENGTH) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) Validate(software.amazon.awssdk.utils.Validate) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) Logger(software.amazon.awssdk.utils.Logger) ContentStreamProvider(software.amazon.awssdk.http.ContentStreamProvider) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) SdkHttpConfigurationOption(software.amazon.awssdk.http.SdkHttpConfigurationOption) Collectors(java.util.stream.Collectors) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) KeyManager(javax.net.ssl.KeyManager) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) CLIENT_ERROR(software.amazon.awssdk.http.HttpStatusFamily.CLIENT_ERROR) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) List(java.util.List) X509TrustManager(javax.net.ssl.X509TrustManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Optional(java.util.Optional) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) SERVER_ERROR(software.amazon.awssdk.http.HttpStatusFamily.SERVER_ERROR) IoUtils(software.amazon.awssdk.utils.IoUtils) InputStream(java.io.InputStream) HttpExecuteRequest(software.amazon.awssdk.http.HttpExecuteRequest) HttpURLConnection(java.net.HttpURLConnection)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 HttpURLConnection (java.net.HttpURLConnection)1 URI (java.net.URI)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 X509Certificate (java.security.cert.X509Certificate)1 Duration (java.time.Duration)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 KeyManager (javax.net.ssl.KeyManager)1 SSLContext (javax.net.ssl.SSLContext)1