aws / aws/aws-sdk-java-v2

Announcement: Apache 5 is now the default HTTP Client

Open
#7,007 0 comments 0 reactions 0 assignees View on GitHub
announcement
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

Starting in Java SDK `v2.46.0`, SDK sync clients will use Apache 5 as the default HTTP client, without the need to manually add `apache5-client` as a dependency. This change comes after support for Apache 5 was added in `v2.41.0`.

Simply add the service module to your project, and the sync client will use Apache 5 HTTP client by default:

```

software.amazon.awssdk
s3

```
```
// Apache5HttpClient is used here
S3Client client = S3Client.create();
```
If you want to customize the client settings, use the Apache5HttpClient.builder() as before:

```
S3Client client = S3Client.builder()
.httpClientBuilder(Apache5HttpClient.builder()
.maxConnections(100)
.connectionTimeout(Duration.ofSeconds(5)))
.build();
```

### Notable changes

* **Logger name differences** - Apache 5 uses different logger names than Apache 4. If you have logging configurations targeting Apache 4 logger names, you must update them. Please refer to the Apache 5 documentation, and see an example of SDK wire logging with Apache5HttpClient in the [Developer Guide - Logging](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/logging-slf4j.html#sdk-java-logging-verbose).
* **Increase in jar size** - If you explicitly depend on `apache-client`, after this change the `apache5-client` will be also added to the classpath, resulting in a ~2.3 MB increase in bundled artifact size. To avoid the jar size increase you can exclude the `apache5-client` as a workaround:
```

software.amazon.awssdk
s3


software.amazon.awssdk
apache5-client

software.amazon.awssdk
apache-client

```
Note that we recommend to fully migrate to use `apache5-client` instead of `apache-client`.

* **Expect: 100-Continue is disabled by default** - It was enabled by default in Apache 4. See [PR #6828](https://github.com/aws/aws-sdk-java-v2/pull/6828) for details. To re-enable in the Apache5 client, set the expectContinueEnabled configuration to True:
```
S3Client client = S3Client.builder()
.httpClientBuilder(Apache5HttpClient.builder()
.expectContinueEnabled(Boolean.TRUE))
.build();
```
* **Network permissions needed for Java SecurityManager** - Apache HttpClient 5.6 enables TCP keep-alive socket options by default (`TCP_KEEPIDLE`, `TCP_KEEPINTERVAL`, `TCP_KEEPCOUNT`), which require `jdk.net.NetworkPermission` when a SecurityManager is active. Without these permissions, requests fail with `java.security.AccessControlException: access denied`. These permissions were not required for Apache 4.x. If you use SecurityManager and start to see `AccessControlExceptions` after the upgrade, you need to grant permission to those TCP keep-alive options, see [PR #6974](https://github.com/aws/aws-sdk-java-v2/pull/6974) for details.

## Feedback

If you have questions, find a bug or have a feature request for the client to better suit your needs, please reach out to us by creating a new [GitHub issue](https://github.com/aws/aws-sdk-java-v2/issues/new/choose).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.