Skip to content

sigpwned/aws-java-sdk-v2-java-11-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-java-sdk-v2-java-11-client tests Maven Central

An implementation of the AWS Java SDK v2 HTTP Client SPI using the Java 11 HttpClient.

It was pulled from the @aws/aws-java-sdk-v2 java-11-http-client branch.

It is very much a work in progress. Help, feedback, and PRs are all welcome and (greatly) appreciated!

Getting started

To include the asynchronous client in your code, simply add the following Maven dependency:

    <dependency>
        <groupId>com.sigpwned</groupId>
        <artifactId>awssdkv2-java11-async-client</artifactId>
        <version>2.37.7.0-b0</version>
    </dependency>

Background

AWS Java SDK v2 has an HTTP client service provider interface, which it leverages to provide a variety of managed HTTP clients (e.g., software.amazon.awssdk:url-connection-client). It would be usefult to have an additional AWS HTTP Client backed by the Java 11 HttpClient for a variety of reasons:

  • Reduced runtime size
  • Reduced cold start time
  • Simplified dependency management
  • Virtual Thread readiness

So far, Amazon itself seems reluctant to provide such an implementation. And that's OK! Amazon has its own values, priorities, and resource constraints.

But they've also given us the tools to build such a client ourselves. This project is that implementation.

Implementations

More information about the "official" Amazon implementations is available here.

Integration tests against live or mock services remain a work-in-progress.

Asynchronous

The awssdkv2-java11-async-client is an asynchronous implementation of the SdkAsyncHttpClient asynchronous HTTP client SPI from the AWS Java SDK v2. You can compare it to the two asynchronous clients Amazon currently supports for that library:

This implementation can be used like any other implementation, for example for use in the SQS client:

    SqsAsyncClient client = SqsAsyncClient.builder()
        .httpClient(Java11AsyncHttpClient.create())
        .region(Region.US_EAST_1)
        .build();

There are a few caveats about its usage as compared to other clients due to differences in the underlying HttpClient implementation:

  • There is no support for read and write timeouts, per JDK-8258397. Rather, the client can be configured to use a request timeout, which limits how long the client waits until HTTP response headers are received, but that's it.
  • Proxy authentication is not supported out of the box. Per JDK-8229962, configuring proxy authentication on HttpClient requires providing some process-level configuration parameters up front, so proxy authentication is up to the user, at least for now.
  • There is a difference in behavior for canceled HTTP requests between Java 11 and Java 15, and Java 16 and later. Per JDK-8245462, before Java 16, calling CompletableFuture#cancel(boolean) on the result of execute() does nothing, whereas starting with Java 16 it now attempts to cancel the request in-flight.
  • The client does not close connections after receiving 5XX responses from the server, which is technically part of the requirements for other HTTP clients. The reason for the requirement is not documented, so it's not clear what negative effect(s) this difference will have in practice, if any.
  • There may be some slight differences in how Expect: 100-continue is handled versus other clients.

Prior Art

There are some other implementations using this same approach that were very useful in creating this implementation:

They generally appear to be abandoned, which is why I created this project.

Help Wanted

All feedback -- even if it's just "I tried it, and it worked" -- is welcome, appreciated, and useful! Issues and PRs are even better.

Naturally, all helpers will be added to the contributors.