From 134b7bd7086b68051eb2c61688525e0e0705198b Mon Sep 17 00:00:00 2001 From: Thomas Farr Date: Mon, 11 Nov 2024 14:44:41 +1300 Subject: [PATCH] Also validate URLConnection client Signed-off-by: Thomas Farr --- java-client/build.gradle.kts | 1 + .../transport/aws/AwsSdk2TransportTests.java | 31 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index 0a6745494..3fdaf9f4d 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -229,6 +229,7 @@ dependencies { testImplementation("software.amazon.awssdk", "aws-crt-client", "[2.21,3.0)") testImplementation("software.amazon.awssdk", "apache-client", "[2.21,3.0)") testImplementation("software.amazon.awssdk", "netty-nio-client", "[2.21,3.0)") + testImplementation("software.amazon.awssdk", "url-connection-client", "[2.21,3.0)") testImplementation("software.amazon.awssdk", "sts", "[2.21,3.0)") testImplementation("org.apache.logging.log4j", "log4j-api","[2.17.1,3.0)") diff --git a/java-client/src/test/java/org/opensearch/client/transport/aws/AwsSdk2TransportTests.java b/java-client/src/test/java/org/opensearch/client/transport/aws/AwsSdk2TransportTests.java index 24ff7d25e..25789315f 100644 --- a/java-client/src/test/java/org/opensearch/client/transport/aws/AwsSdk2TransportTests.java +++ b/java-client/src/test/java/org/opensearch/client/transport/aws/AwsSdk2TransportTests.java @@ -68,16 +68,18 @@ import software.amazon.awssdk.http.crt.AwsCrtHttpClient; import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient; import software.amazon.awssdk.http.nio.netty.ProxyConfiguration; +import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.utils.AttributeMap; @RunWith(Parameterized.class) public class AwsSdk2TransportTests { public enum SdkHttpClientType { + APACHE, AWS_CRT, AWS_CRT_ASYNC, - APACHE, - NETTY_NIO_ASYNC + NETTY_NIO_ASYNC, + URL_CONNECTION } private static final String[] TEST_SERVICE_NAMES = { "aoss", "es", "arbitrary" }; @@ -254,9 +256,18 @@ private OpenSearchClient getTestClient() throws URISyntaxException { .build(); } + URI proxyEndpoint = new URI("http://localhost:" + proxy.getPort()); + SdkHttpClient sdkHttpClient = null; SdkAsyncHttpClient sdkAsyncHttpClient = null; switch (sdkHttpClientType) { + case APACHE: + software.amazon.awssdk.http.apache.ProxyConfiguration proxyConfig = software.amazon.awssdk.http.apache.ProxyConfiguration + .builder() + .endpoint(proxyEndpoint) + .build(); + sdkHttpClient = ApacheHttpClient.builder().proxyConfiguration(proxyConfig).buildWithDefaults(sdkHttpClientConfig); + break; case AWS_CRT: sdkHttpClient = AwsCrtHttpClient.builder() .proxyConfiguration(p -> p.scheme("http").host("localhost").port(proxy.getPort())) @@ -267,13 +278,6 @@ private OpenSearchClient getTestClient() throws URISyntaxException { .proxyConfiguration(p -> p.scheme("http").host("localhost").port(proxy.getPort())) .buildWithDefaults(sdkHttpClientConfig); break; - case APACHE: - software.amazon.awssdk.http.apache.ProxyConfiguration proxyConfig = software.amazon.awssdk.http.apache.ProxyConfiguration - .builder() - .endpoint(new URI("http://localhost:" + proxy.getPort())) - .build(); - sdkHttpClient = ApacheHttpClient.builder().proxyConfiguration(proxyConfig).buildWithDefaults(sdkHttpClientConfig); - break; case NETTY_NIO_ASYNC: ProxyConfiguration nettyProxyConfig = software.amazon.awssdk.http.nio.netty.ProxyConfiguration.builder() .scheme("http") @@ -284,6 +288,11 @@ private OpenSearchClient getTestClient() throws URISyntaxException { .proxyConfiguration(nettyProxyConfig) .buildWithDefaults(sdkHttpClientConfig); break; + case URL_CONNECTION: + sdkHttpClient = UrlConnectionHttpClient.builder() + .proxyConfiguration(p -> p.endpoint(proxyEndpoint)) + .buildWithDefaults(sdkHttpClientConfig); + break; default: throw new IllegalArgumentException("Unknown SdkHttpClientType: " + sdkHttpClientType); } @@ -417,8 +426,8 @@ private void assertSigV4Request( String expectedContentLength = String.valueOf(contentLength); if (contentLength == 0 - && (sdkHttpClientType == SdkHttpClientType.AWS_CRT || sdkHttpClientType == SdkHttpClientType.NETTY_NIO_ASYNC)) { - // AWS CRT and Netty NIO Async clients do not set content-length for empty bodies + && (sdkHttpClientType == SdkHttpClientType.AWS_CRT || sdkHttpClientType == SdkHttpClientType.NETTY_NIO_ASYNC || sdkHttpClientType == SdkHttpClientType.URL_CONNECTION)) { + // AWS CRT, Netty NIO and URLConnection clients do not set content-length for empty bodies expectedContentLength = null; }