Skip to content

Commit 5983aea

Browse files
authored
AwsSdk2Transport throw exception when using ApacheHttpClient to make an unsupported DELETE/GET request with a body (#1256) (#1288)
* AwsSdk2Transport throw exception when using ApacheHttpClient to make an unsupported DELETE/GET request with a body The AWS SDK's ApacheHttpClient implementation does not send the request body on DELETE or GET requests, https://github.com/aws/aws-sdk-java-v2/blob/master/http-clients/apache-client/src/main/java/software/amazon/awssdk/http/apache/internal/impl/ApacheHttpRequestFactory.java#L118-L137. Additionally moves to the supported `AwsV4HttpSigner` as `Aws4Signer` is now deprecated: https://github.com/aws/aws-sdk-java-v2/blob/88abec27e7d5d35b21545c7e05875a7cc3d0f46e/core/auth/src/main/java/software/amazon/awssdk/auth/signer/Aws4Signer.java Signed-off-by: Thomas Farr <[email protected]> * Add guide note Signed-off-by: Thomas Farr <[email protected]> * Fix javadoc Signed-off-by: Thomas Farr <[email protected]> * Re-use ContentStreamProvider Signed-off-by: Thomas Farr <[email protected]> * Also validate URLConnection client Signed-off-by: Thomas Farr <[email protected]> * spotless Signed-off-by: Thomas Farr <[email protected]> * Test HEAD and OPTIONS Signed-off-by: Thomas Farr <[email protected]> --------- Signed-off-by: Thomas Farr <[email protected]> (cherry picked from commit e8e3a99)
1 parent a7a9a0b commit 5983aea

File tree

8 files changed

+995
-83
lines changed

8 files changed

+995
-83
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
77
### Dependencies
88

99
### Changed
10+
- Changed AwsSdk2Transport to pre-emptively throw an exception when using AWS SDK's ApacheHttpClient to make an unsupported DELETE/GET request with a body ([#1256](https://github.com/opensearch-project/opensearch-java/pull/1256))
1011

1112
### Deprecated
1213

guides/auth.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77

88
Requests to [OpenSearch Service and OpenSearch Serverless](https://docs.aws.amazon.com/opensearch-service/index.html) must be signed using the AWS signing protocol. Use `AwsSdk2Transport` to send signed requests.
99

10+
> ⚠️ **Warning** ⚠️
11+
> Using `software.amazon.awssdk.http.apache.ApacheHttpClient` is discouraged as it does not support request bodies on GET or DELETE requests.
12+
> This leads to incorrect handling of requests such as `OpenSearchClient.clearScroll()` and `OpenSearchClient.deletePit()`.
13+
> As such `AwsSdk2Transport` will throw a `TransportException` if an unsupported request is encountered while using `ApacheHttpClient`.
14+
1015
```java
11-
SdkHttpClient httpClient = ApacheHttpClient.builder().build();
16+
SdkHttpClient httpClient = AwsCrtHttpClient.builder().build();
1217

1318
OpenSearchClient client = new OpenSearchClient(
1419
new AwsSdk2Transport(
1520
httpClient,
1621
"search-...us-west-2.es.amazonaws.com", // OpenSearch endpoint, without https://
17-
"es" // signing service name, use "aoss" for OpenSearch Serverless
22+
"es", // signing service name, use "aoss" for OpenSearch Serverless
1823
Region.US_WEST_2, // signing service region
1924
AwsSdk2TransportOptions.builder().build()
2025
)

java-client/build.gradle.kts

+23-10
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,13 @@ tasks.withType<ProcessResources> {
102102

103103
tasks.withType<Javadoc>().configureEach{
104104
options {
105+
this as StandardJavadocDocletOptions
105106
encoding = "UTF-8"
107+
addMultilineStringsOption("tag").setValue(listOf(
108+
"apiNote:a:API Note:",
109+
"implSpec:a:Implementation Requirements:",
110+
"implNote:a:Implementation Note:",
111+
))
106112
}
107113
}
108114

@@ -170,7 +176,6 @@ val integrationTest = task<Test>("integrationTest") {
170176
val opensearchVersion = "2.12.0"
171177

172178
dependencies {
173-
174179
val jacksonVersion = "2.17.0"
175180
val jacksonDatabindVersion = "2.17.0"
176181

@@ -200,7 +205,6 @@ dependencies {
200205
implementation("jakarta.annotation", "jakarta.annotation-api", "1.3.5")
201206

202207
// Apache 2.0
203-
204208
implementation("com.fasterxml.jackson.core", "jackson-core", jacksonVersion)
205209
implementation("com.fasterxml.jackson.core", "jackson-databind", jacksonDatabindVersion)
206210
testImplementation("com.fasterxml.jackson.datatype", "jackson-datatype-jakarta-jsonp", jacksonVersion)
@@ -213,16 +217,21 @@ dependencies {
213217
implementation("org.apache.httpcomponents.core5", "httpcore5-h2", "5.3.1")
214218

215219
// For AwsSdk2Transport
216-
"awsSdk2SupportCompileOnly"("software.amazon.awssdk","sdk-core","[2.15,3.0)")
217-
"awsSdk2SupportCompileOnly"("software.amazon.awssdk","auth","[2.15,3.0)")
218-
testImplementation("software.amazon.awssdk","sdk-core","[2.15,3.0)")
219-
testImplementation("software.amazon.awssdk","auth","[2.15,3.0)")
220-
testImplementation("software.amazon.awssdk","aws-crt-client","[2.15,3.0)")
221-
testImplementation("software.amazon.awssdk","apache-client","[2.15,3.0)")
222-
testImplementation("software.amazon.awssdk","sts","[2.15,3.0)")
220+
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "sdk-core", "[2.21,3.0)")
221+
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "auth", "[2.21,3.0)")
222+
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "http-auth-aws", "[2.21,3.0)")
223+
testImplementation("software.amazon.awssdk", "sdk-core", "[2.21,3.0)")
224+
testImplementation("software.amazon.awssdk", "auth", "[2.21,3.0)")
225+
testImplementation("software.amazon.awssdk", "http-auth-aws", "[2.21,3.0)")
226+
testImplementation("software.amazon.awssdk", "aws-crt-client", "[2.21,3.0)")
227+
testImplementation("software.amazon.awssdk", "apache-client", "[2.21,3.0)")
228+
testImplementation("software.amazon.awssdk", "netty-nio-client", "[2.21,3.0)")
229+
testImplementation("software.amazon.awssdk", "url-connection-client", "[2.21,3.0)")
230+
testImplementation("software.amazon.awssdk", "sts", "[2.21,3.0)")
231+
223232
testImplementation("org.apache.logging.log4j", "log4j-api","[2.17.1,3.0)")
224233
testImplementation("org.apache.logging.log4j", "log4j-core","[2.17.1,3.0)")
225-
234+
226235
// EPL-2.0 OR BSD-3-Clause
227236
// https://eclipse-ee4j.github.io/yasson/
228237
implementation("org.eclipse", "yasson", "2.0.2")
@@ -234,6 +243,10 @@ dependencies {
234243
testImplementation("junit", "junit" , "4.13.2") {
235244
exclude(group = "org.hamcrest")
236245
}
246+
247+
// The Bouncy Castle License (MIT): https://www.bouncycastle.org/licence.html
248+
testImplementation("org.bouncycastle", "bcprov-lts8on", "2.73.6")
249+
testImplementation("org.bouncycastle", "bcpkix-lts8on", "2.73.6")
237250
}
238251

239252
licenseReport {

0 commit comments

Comments
 (0)