AWS Developer Tools Blog

GA Release of the AWS SDK Java 2.x HTTP Client built on Apache HttpClient 5.6

If you’re using the Apache HttpClient 4.5.x with the AWS SDK for Java 2.x, you may have encountered dependency alerts for Jakarta Commons Logging (JCL) dependencies, concerns about long-term maintenance support, or compatibility issues with Java 21’s virtual threads. The new Apache 5 HTTP client solves these problems.

In this post, you’ll learn how to add the Apache 5 HTTP client to your project, configure it for your needs, and migrate from the 4.5.x version.

What’s new

  • Modern logging: Replaces the outdated JCL dependency with Simple Logging Facade for Java (SLF4J), giving you better compatibility with modern logging frameworks like Logback and Log4j2
  • Virtual thread support: Full compatibility with Java 21’s virtual threads for improved concurrency
  • Active maintenance: Apache HttpClient 5.x receives regular security updates and bug fixes

This client is available alongside the existing SDK HTTP clients: Apache HttpClient 4.5.x, Netty, URL Connection, and AWS CRT HTTP client. The new apache5-client Maven artifact lets you use both Apache versions in the same project without conflicts.

Getting started

Using the Apache 5 HTTP client in your SDK can require as little as a single step. If you’re coming from the Apache 4 client and want to set specific configurations, the new Apache 5 client offers identical options.

Add the Apache 5 client dependency

To begin using the Apache 5 HTTP client implementation, add the following dependency to your project:

<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>apache5-client</artifactId>
    <version>2.41.26</version>
</dependency>

If you just want to use all the default configurations, then you do not need to configure anything else; your sync clients will use the Apache5 client under the hood.

S3Client s3Client = S3Client.create();

Advanced configuration example

If you want to configure certain options on the client, then just like with all of our clients, you can use Apache5HttpClient.builder() to obtain a builder and set the options you would like to:

Apache5HttpClient httpClient = Apache5HttpClient.builder()
    .connectionTimeout(Duration.ofSeconds(30))
    .maxConnections(100)
    .build();

DynamoDbClient dynamoDbClient = DynamoDbClient.builder()
    .httpClient(httpClient)
    .build();

Migrate from Apache 4.5.x

If you’re using the default Apache HTTP client, migration is straightforward:

  1. Add the apache5-client dependency shown above
  2. Update any explicit ApacheHttpClient references to Apache5HttpClient

The API remains consistent with other HTTP client implementations in the SDK. Note that like the 4.5.x client, this implementation supports synchronous service clients only.

Cleaning up

When you’re done with a service client, close it to release resources:


s3Client.close();

If you created a shared Apache5HttpClient instance, close it separately after closing the service clients that use it.

Conclusion

In this blog post, we showed you how to get started with the new Apache 5 HTTP client in the AWS SDK for Java 2.x, which uses Apache HttpClient 5.6.x. Please share your experience and any feature requests by opening a GitHub issue.


Dongie Agnir

Dongie Agnir

Dongie Agnir is a Senior Engineer on the AWS SDK for Java.