diff --git a/.changes/next-release/bugfix-ApacheHttpClient-d9de03d.json b/.changes/next-release/bugfix-ApacheHttpClient-d9de03d.json new file mode 100644 index 000000000000..d63d9c52eedf --- /dev/null +++ b/.changes/next-release/bugfix-ApacheHttpClient-d9de03d.json @@ -0,0 +1,5 @@ +{ + "category": "Apache Http Client", + "type": "bugfix", + "description": "Disable apache normalization to handle breaking change introduced in apache httpclient `4.5.7`. See [aws/aws-sdk-java[#1919](https://github.com/aws/aws-sdk-java-v2/issues/1919)](https://github.com/aws/aws-sdk-java/issues/1919) for more information." +} diff --git a/.changes/next-release/feature-AWSSDKforJavav2-f344377.json b/.changes/next-release/feature-AWSSDKforJavav2-f344377.json new file mode 100644 index 000000000000..c1c5e0cca05a --- /dev/null +++ b/.changes/next-release/feature-AWSSDKforJavav2-f344377.json @@ -0,0 +1,5 @@ +{ + "category": "AWS SDK for Java v2", + "type": "feature", + "description": "Update Apache http client version to `4.5.9`." +} diff --git a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java index 00e903a63e59..d2e0d4060510 100644 --- a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java +++ b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java @@ -86,6 +86,8 @@ private void addRequestConfig(final HttpRequestBase base, .setSocketTimeout(saturatedCast(requestConfig.socketTimeout().toMillis())) .setLocalAddress(requestConfig.localAddress()); + ApacheUtils.disableNormalizeUri(requestConfigBuilder); + /* * Enable 100-continue support for PUT operations, since this is * where we're potentially uploading large amounts of data and want diff --git a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java index 7b42eb6820db..ebcd66711810 100644 --- a/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java +++ b/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/utils/ApacheUtils.java @@ -24,6 +24,7 @@ import org.apache.http.auth.NTCredentials; import org.apache.http.client.AuthCache; import org.apache.http.client.CredentialsProvider; +import org.apache.http.client.config.RequestConfig; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.auth.BasicScheme; @@ -31,9 +32,11 @@ import org.apache.http.impl.client.BasicCredentialsProvider; import software.amazon.awssdk.annotations.SdkInternalApi; import software.amazon.awssdk.http.apache.ProxyConfiguration; +import software.amazon.awssdk.utils.Logger; @SdkInternalApi public final class ApacheUtils { + private static final Logger logger = Logger.loggerFor(ApacheUtils.class); private ApacheUtils() { } @@ -59,10 +62,41 @@ public static HttpEntity newBufferedHttpEntity(HttpEntity entity) { public static HttpClientContext newClientContext(ProxyConfiguration proxyConfiguration) { HttpClientContext clientContext = new HttpClientContext(); addPreemptiveAuthenticationProxy(clientContext, proxyConfiguration); + + RequestConfig.Builder builder = RequestConfig.custom(); + disableNormalizeUri(builder); + + clientContext.setRequestConfig(builder.build()); return clientContext; } + /** + * From Apache v4.5.8, normalization should be disabled or AWS requests with special characters in URI path will fail + * with Signature Errors. + *

+ * setNormalizeUri is added only in 4.5.8, so customers using the latest version of SDK with old versions (4.5.6 or less) + * of Apache httpclient will see NoSuchMethodError. Hence this method will suppress the error. + * + * Do not use Apache version 4.5.7 as it breaks URI paths with special characters and there is no option + * to disable normalization. + *

+ * + * For more information, See https://github.com/aws/aws-sdk-java/issues/1919 + */ + public static void disableNormalizeUri(RequestConfig.Builder requestConfigBuilder) { + try { + requestConfigBuilder.setNormalizeUri(false); + } catch (NoSuchMethodError error) { + // setNormalizeUri method was added in httpclient 4.5.8 + logger.warn(() -> "NoSuchMethodError was thrown when disabling normalizeUri. This indicates you are using an old " + + "version (< 4.5.8) of Apache http " + + "client. It is recommended to use http client version >= 4.5.9 to avoid the breaking change " + + "introduced in apache client 4.5.7 and the latency in exception handling. " + + "See https://github.com/aws/aws-sdk-java/issues/1919 for more information"); + } + } + /** * Returns a new Credentials Provider for use with proxy authentication. */ diff --git a/pom.xml b/pom.xml index 37ac767ee2cd..74e8a26f4234 100644 --- a/pom.xml +++ b/pom.xml @@ -145,7 +145,7 @@ 1.8.2 1.8 - 4.5.6 + 4.5.9 4.4.10 diff --git a/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java b/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java index d429f9f6d877..761dd0a201e5 100644 --- a/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java +++ b/services/s3/src/it/java/software/amazon/awssdk/services/s3/S3ListObjectsV2IntegrationTest.java @@ -89,8 +89,9 @@ public static void createResources() throws Exception { createKey("key-" + numberFormatter.format(i)); } createKey("aaaaa"); - createKey("aaaaa/aaaaa"); createKey("aaaaa/aaaaa/aaaaa"); + createKey("aaaaa/aaaaa+a"); + createKey("aaaaa/aaaaa//aaaaa"); createKey(KEY_NAME_WITH_SPECIAL_CHARS); }