Skip to content

Commit 24438e8

Browse files
committed
Revert "Updated snap shot after merge from master"
This reverts commit 64f7d33.
1 parent 64f7d33 commit 24438e8

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

http-clients/apache5-client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>http-clients</artifactId>
2323
<groupId>software.amazon.awssdk</groupId>
24-
<version>2.31.53-SNAPSHOT</version>
24+
<version>2.31.51-SNAPSHOT</version>
2525
</parent>
2626

2727
<artifactId>apache5-client</artifactId>

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/impl/Apache5HttpRequestFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ private void addRequestConfig(HttpUriRequestBase base,
100100
.setResponseTimeout(saturatedCast(requestConfig.socketTimeout().toMillis()), TimeUnit.MILLISECONDS);
101101
// TODO as part of removed API : .setLocalAddress(requestConfig.localAddress());
102102

103+
Apache5Utils.disableNormalizeUri(requestConfigBuilder);
104+
103105
/*
104106
* Enable 100-continue support for PUT operations, since this is
105107
* where we're potentially uploading large amounts of data and want

http-clients/apache5-client/src/main/java/software/amazon/awssdk/http/apache5/internal/utils/Apache5Utils.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,28 @@
3030
import software.amazon.awssdk.annotations.SdkInternalApi;
3131
import software.amazon.awssdk.http.apache5.ProxyConfiguration;
3232
import software.amazon.awssdk.utils.Logger;
33+
import software.amazon.awssdk.utils.ReflectionMethodInvoker;
3334

3435
@SdkInternalApi
3536
public final class Apache5Utils {
3637
private static final Logger logger = Logger.loggerFor(Apache5Utils.class);
38+
private static final ReflectionMethodInvoker<RequestConfig.Builder, RequestConfig.Builder> NORMALIZE_URI_INVOKER;
39+
40+
static {
41+
// Attempt to initialize the invoker once on class-load. If it fails, it will not be attempted again, but we'll
42+
// use that opportunity to log a warning.
43+
NORMALIZE_URI_INVOKER =
44+
new ReflectionMethodInvoker<>(RequestConfig.Builder.class,
45+
RequestConfig.Builder.class,
46+
"setNormalizeUri",
47+
boolean.class);
48+
49+
try {
50+
NORMALIZE_URI_INVOKER.initialize();
51+
} catch (NoSuchMethodException ignored) {
52+
noSuchMethodThrownByNormalizeUriInvoker();
53+
}
54+
}
3755

3856
private Apache5Utils() {
3957
}
@@ -61,11 +79,36 @@ public static HttpClientContext newClientContext(ProxyConfiguration proxyConfigu
6179
addPreemptiveAuthenticationProxy(clientContext, proxyConfiguration);
6280

6381
RequestConfig.Builder builder = RequestConfig.custom();
82+
disableNormalizeUri(builder);
83+
6484
clientContext.setRequestConfig(builder.build());
6585
return clientContext;
6686

6787
}
6888

89+
/**
90+
* From Apache v4.5.8, normalization should be disabled or AWS requests with special characters in URI path will fail
91+
* with Signature Errors.
92+
* <p>
93+
* setNormalizeUri is added only in 4.5.8, so customers using the latest version of SDK with old versions (4.5.6 or less)
94+
* of Apache httpclient will see NoSuchMethodError. Hence this method will suppress the error.
95+
*
96+
* Do not use Apache version 4.5.7 as it breaks URI paths with special characters and there is no option
97+
* to disable normalization.
98+
* </p>
99+
*
100+
* For more information, See https://github.com/aws/aws-sdk-java/issues/1919
101+
*/
102+
public static void disableNormalizeUri(RequestConfig.Builder requestConfigBuilder) {
103+
// For efficiency, do not attempt to call the invoker again if it failed to initialize on class-load
104+
if (NORMALIZE_URI_INVOKER.isInitialized()) {
105+
try {
106+
NORMALIZE_URI_INVOKER.invoke(requestConfigBuilder, false);
107+
} catch (NoSuchMethodException ignored) {
108+
noSuchMethodThrownByNormalizeUriInvoker();
109+
}
110+
}
111+
}
69112

70113
/**
71114
* Returns a new Credentials Provider for use with proxy authentication.
@@ -111,4 +154,13 @@ private static void addPreemptiveAuthenticationProxy(HttpClientContext clientCon
111154
}
112155
}
113156

157+
// Just log and then swallow the exception
158+
private static void noSuchMethodThrownByNormalizeUriInvoker() {
159+
// setNormalizeUri method was added in httpclient 4.5.8
160+
logger.warn(() -> "NoSuchMethodException was thrown when disabling normalizeUri. This indicates you are using "
161+
+ "an old version (< 4.5.8) of Apache http client. It is recommended to use http client "
162+
+ "version >= 4.5.9 to avoid the breaking change introduced in apache client 4.5.7 and "
163+
+ "the latency in exception handling. See https://github.com/aws/aws-sdk-java/issues/1919"
164+
+ " for more information");
165+
}
114166
}

test/architecture-tests/archunit_store/4195d6e3-8849-4e5a-848d-04f810577cd3

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ Method <software.amazon.awssdk.http.SystemPropertyTlsKeyManagersProvider.keyMana
1313
Method <software.amazon.awssdk.http.apache.ApacheHttpClient$ApacheConnectionManagerFactory.getSslContext(software.amazon.awssdk.utils.AttributeMap)> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier)> in (ApacheHttpClient.java:699)
1414
Method <software.amazon.awssdk.http.apache.internal.RepeatableInputStreamRequestEntity.parseContentLength(java.lang.String)> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier)> in (RepeatableInputStreamRequestEntity.java:113)
1515
Method <software.amazon.awssdk.http.apache.internal.utils.ApacheUtils.noSuchMethodThrownByNormalizeUriInvoker()> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier)> in (ApacheUtils.java:162)
16-
Method <software.amazon.awssdk.http.apache5.internal.RepeatableInputStreamRequestEntity.parseContentLength(java.lang.String)> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier)> in (RepeatableInputStreamRequestEntity.java:131)
17-
Method <software.amazon.awssdk.http.apache5.internal.RepeatableInputStreamRequestEntity.parseContentType(java.lang.String)> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier)> in (RepeatableInputStreamRequestEntity.java:143)
1816
Method <software.amazon.awssdk.http.nio.netty.internal.utils.NettyUtils.warnIfNotInEventLoop(io.netty.channel.EventLoop)> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier, java.lang.Throwable)> in (NettyUtils.java:289)
1917
Method <software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient.getSslContext(software.amazon.awssdk.utils.AttributeMap)> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier)> in (UrlConnectionHttpClient.java:263)
2018
Method <software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher.publish(software.amazon.awssdk.metrics.MetricCollection)> calls method <software.amazon.awssdk.utils.Logger.warn(java.util.function.Supplier, java.lang.Throwable)> in (CloudWatchMetricPublisher.java:293)

0 commit comments

Comments
 (0)