Skip to content

Commit 4279d36

Browse files
authored
Revert throwing on AwsSdk2 + ApacheHttpClient (#1333)
* Revert throwing on AwsSdk2 + ApacheHttpClient Signed-off-by: Thomas Farr <[email protected]> * Add PR number Signed-off-by: Thomas Farr <[email protected]> --------- Signed-off-by: Thomas Farr <[email protected]>
1 parent d3509b5 commit 4279d36

File tree

5 files changed

+16
-57
lines changed

5 files changed

+16
-57
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ This section is for maintaining a changelog for all breaking changes for the cli
4343
### Added
4444

4545
### Dependencies
46+
- Upgraded aws-sdk-java dependencies to at least `2.19.22` ([#1333](https://github.com/opensearch-project/opensearch-java/pull/1333))
4647

4748
### Changed
4849

4950
### Deprecated
5051

5152
### Removed
53+
- Removed throwing of exception when using `AwsSdk2Transport` with AWS SDK's `ApacheHttpClient` to make an DELETE/GET request with a body ([#1333](https://github.com/opensearch-project/opensearch-java/pull/1333))
5254

5355
### Fixed
5456
- Fixed an issue where `FieldSort` was not implementing `SortOptionsVariant` ([#1323](https://github.com/opensearch-project/opensearch-java/pull/1323))

guides/auth.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
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

1010
> ⚠️ **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`.
11+
> If you are using `software.amazon.awssdk.http.apache.ApacheHttpClient` please ensure you use at least version `2.29.22` as earlier versions do not support request bodies on GET or DELETE requests, which leads to incorrect handling of requests such as `OpenSearchClient.clearScroll()` and `OpenSearchClient.deletePit()`.
1412
1513
```java
1614
SdkHttpClient httpClient = AwsCrtHttpClient.builder().build();

java-client/build.gradle.kts

+11-11
Original file line numberDiff line numberDiff line change
@@ -220,17 +220,17 @@ dependencies {
220220
testImplementation("com.fasterxml.jackson.datatype", "jackson-datatype-jakarta-jsonp", jacksonVersion)
221221

222222
// For AwsSdk2Transport
223-
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "sdk-core", "[2.21,3.0)")
224-
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "auth", "[2.21,3.0)")
225-
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "http-auth-aws", "[2.21,3.0)")
226-
testImplementation("software.amazon.awssdk", "sdk-core", "[2.21,3.0)")
227-
testImplementation("software.amazon.awssdk", "auth", "[2.21,3.0)")
228-
testImplementation("software.amazon.awssdk", "http-auth-aws", "[2.21,3.0)")
229-
testImplementation("software.amazon.awssdk", "aws-crt-client", "[2.21,3.0)")
230-
testImplementation("software.amazon.awssdk", "apache-client", "[2.21,3.0)")
231-
testImplementation("software.amazon.awssdk", "netty-nio-client", "[2.21,3.0)")
232-
testImplementation("software.amazon.awssdk", "url-connection-client", "[2.21,3.0)")
233-
testImplementation("software.amazon.awssdk", "sts", "[2.21,3.0)")
223+
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "sdk-core", "[2.29.22,3.0)")
224+
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "auth", "[2.29.22,3.0)")
225+
"awsSdk2SupportCompileOnly"("software.amazon.awssdk", "http-auth-aws", "[2.29.22,3.0)")
226+
testImplementation("software.amazon.awssdk", "sdk-core", "[2.29.22,3.0)")
227+
testImplementation("software.amazon.awssdk", "auth", "[2.29.22,3.0)")
228+
testImplementation("software.amazon.awssdk", "http-auth-aws", "[2.29.22,3.0)")
229+
testImplementation("software.amazon.awssdk", "aws-crt-client", "[2.29.22,3.0)")
230+
testImplementation("software.amazon.awssdk", "apache-client", "[2.29.22,3.0)")
231+
testImplementation("software.amazon.awssdk", "netty-nio-client", "[2.29.22,3.0)")
232+
testImplementation("software.amazon.awssdk", "url-connection-client", "[2.29.22,3.0)")
233+
testImplementation("software.amazon.awssdk", "sts", "[2.29.22,3.0)")
234234

235235
testImplementation("org.apache.logging.log4j", "log4j-api","[2.17.1,3.0)")
236236
testImplementation("org.apache.logging.log4j", "log4j-core","[2.17.1,3.0)")

java-client/src/main/java/org/opensearch/client/transport/aws/AwsSdk2Transport.java

+1-20
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public class AwsSdk2Transport implements OpenSearchTransport {
8585

8686
private static final byte[] NO_BYTES = new byte[0];
8787
private final SdkAutoCloseable httpClient;
88-
private final boolean isApacheHttpClient;
8988
private final String host;
9089
private final String signingServiceName;
9190
private final Region signingRegion;
@@ -195,8 +194,6 @@ private AwsSdk2Transport(
195194
) {
196195
Objects.requireNonNull(host, "Target OpenSearch service host must not be null");
197196
this.httpClient = httpClient;
198-
this.isApacheHttpClient = httpClient instanceof SdkHttpClient
199-
&& httpClient.getClass().getName().equals("software.amazon.awssdk.http.apache.ApacheHttpClient");
200197
this.host = host;
201198
this.signingServiceName = signingServiceName;
202199
this.signingRegion = signingRegion;
@@ -299,25 +296,9 @@ private <RequestT> SignedRequest prepareRequest(
299296
Endpoint<RequestT, ?, ?> endpoint,
300297
@CheckForNull TransportOptions options,
301298
@CheckForNull OpenSearchRequestBodyBuffer body
302-
) throws UnsupportedEncodingException, TransportException {
299+
) throws UnsupportedEncodingException {
303300
SdkHttpMethod method = SdkHttpMethod.fromValue(endpoint.method(request));
304301

305-
// AWS Apache Http Client only supports request bodies on PATCH, POST & PUT requests.
306-
// See:
307-
// 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
308-
if (isApacheHttpClient
309-
&& method != SdkHttpMethod.PATCH
310-
&& method != SdkHttpMethod.POST
311-
&& method != SdkHttpMethod.PUT
312-
&& body != null
313-
&& body.getContentLength() > 0) {
314-
throw new TransportException(
315-
"AWS SDK's ApacheHttpClient does not support request bodies for HTTP method `"
316-
+ method
317-
+ "`. Please use a different SdkHttpClient implementation."
318-
);
319-
}
320-
321302
SdkHttpFullRequest.Builder req = SdkHttpFullRequest.builder().method(method);
322303

323304
StringBuilder url = new StringBuilder();

java-client/src/test/java/org/opensearch/client/transport/aws/AwsSdk2TransportTests.java

+1-23
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import static org.apache.hc.core5.http.HttpHeaders.CONTENT_TYPE;
1414
import static org.junit.Assert.assertEquals;
1515
import static org.junit.Assert.assertNotNull;
16-
import static org.junit.Assert.assertThrows;
1716

1817
import java.io.ByteArrayInputStream;
1918
import java.io.ByteArrayOutputStream;
@@ -57,7 +56,6 @@
5756
import org.junit.runners.Parameterized;
5857
import org.opensearch.client.opensearch.OpenSearchClient;
5958
import org.opensearch.client.opensearch.generic.Requests;
60-
import org.opensearch.client.transport.TransportException;
6159
import org.opensearch.client.transport.util.FunnellingHttpsProxy;
6260
import org.opensearch.client.transport.util.SelfSignedCertificateAuthority;
6361
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
@@ -410,27 +408,7 @@ private void assertSigV4Request(
410408
String contentSha256,
411409
String expectedSignature
412410
) throws Exception {
413-
OpenSearchClient client = getTestClient();
414-
415-
if (sdkHttpClientType != SdkHttpClientType.APACHE
416-
|| contentLength == 0
417-
|| "PATCH".equals(method)
418-
|| "POST".equals(method)
419-
|| "PUT".equals(method)) {
420-
request.invoke(client);
421-
} else {
422-
// AWS Apache Http Client only supports content on PATCH, POST & PUT requests.
423-
// See:
424-
// 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
425-
assertThrows(
426-
"AWS SDK's ApacheHttpClient does not support request bodies for HTTP method `"
427-
+ method
428-
+ "`. Please use a different SdkHttpClient implementation.",
429-
TransportException.class,
430-
() -> request.invoke(client)
431-
);
432-
return;
433-
}
411+
request.invoke(getTestClient());
434412

435413
assertEquals(1, receivedRequests.size());
436414
ReceivedRequest req = receivedRequests.poll();

0 commit comments

Comments
 (0)