Skip to content

Commit

Permalink
Also validate URLConnection client
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia committed Nov 11, 2024
1 parent 6e4e8c2 commit 134b7bd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
1 change: 1 addition & 0 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand Down Expand Up @@ -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()))
Expand All @@ -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")
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 134b7bd

Please sign in to comment.