In addition to the goals of JEP 110, this JEP will:
- Take into account feedback received on the incubated API,
- Provide a standardized API, in the
java.net.httppackage, based upon the incubated API, and
- Remove the incubated API.
The motivation of this JEP remains the same as that of the motivation of JEP 110.
This JEP proposes to standardize the HTTP Client API that was introduced
as an incubating API in JDK 9 and updated in JDK 10. The incubating API
has received a number of rounds of feedback that have resulted in
significant improvements, but at a high level it remains largely the
same. The API provides non-blocking request and response semantics
CompletableFutures, which can be chained to trigger dependent
actions. Back-pressure and flow-control of request and response bodies is
provided for via the Platform's reactive-streams support in the
While incubating in JDK 9 and JDK 10, the implementation has been almost completely rewritten. The implementation is now completely asynchronous (the previous HTTP/1.1 implementation was blocking). Use of the RX Flow concept has been pushed down into the implementation, which eliminated many of the original custom concepts needed to support HTTP/2. The flow of data can now be more easily traced, from the user-level request publishers and response subscribers all the way down to the underlying socket. This significantly reduces the number of concepts and complexity in the code, and maximizes the possibility of reuse between HTTP/1.1 and HTTP/2.
The module name and the package name of the standard API will be
Changes over what was incubated in JDK 10
The predefined implementation of
BodySubscriber, created through static factory methods, have been moved out to separate non-instantiable utility factory classes, following the pluralized naming convention. This improves readability of these relatively small interfaces.
The names of the static factory methods have also been updated along the following broad categories:
fromXxx: Adapters from standard Subscriber, e.g. takes a
ofXxx: Factories that create a new pre-defined
Body[Publisher|Handler|Subscriber]that perform useful common tasks, such as handling the response body as a String, or streaming the body to a File.
other: Combinators (takes a
BodySubscriber) and other useful operations.
BodyHandlers and corresponding
BodySubscribers have been added, to improve usability in common scenarios:
discard(Object replacement)combined discarding/ignoring the response body and allowing a given replacement. Feedback has indicated that this could appear confusing. It has been removed and replaced with two separate handlers: 1)
discarding(), and 2)
ofLines()that returns a
BodyHandler<Stream<String>>, to support streaming of response body as a
Streamof lines, line by line. Provides similar semantics to that of
fromLineSubscriber, that supports adaptation of response body to a
BodySubscriber.mappingfor general purpose mapping from one response body type to another.
The push promise support has been re-worked to reduce its impact on the API and bring it more in line with regular request/responses. Specifically, the
MultiResultMaphave been removed. Push promises are now handled through a functional interface,
PushPromiseHandler, that is optionally given during a send operation.
HttpClient.Redirectpolicy has been simplified, by replacing
NORMAL. It has been observed that the previously named
SECUREwas not really appropriately named and should be renamed to
NORMAL, since it will likely be suitable for most normal cases. Given the newly named, aforementioned,
SAME_PROTOCOLappears oddly named, possibly confusing, and not likely to be used.
WebSocket.MessageParthas been removed. This enum was used on the receiving side to indicate whether the delivery of a message is complete, or not. It is asymmetric with the sending side, which uses a simple boolean for this purpose. Additionally, it has been observed that handling received messages with a simple boolean significantly reduces and simplifies the receiving code logic. Determination of messages being delivered as a
WHOLE, one of the benefits and the main purposes for the aforementioned
MessagePart, has proved to not carry its own weight.
Existing tests for the incubated API will be updated to use the new standard API. Additional tests will be added to cover all scenarios supported, specifically the upgrade and downgrade between HTTP/1.1 and HTTP/2.
Risks and Assumptions
Code that currently depends upon the incubated HTTP Client API will need to be updated, at the very minimum to change its package imports. This is no different than for any other incubated feature. Code depending upon incubating modules already receives an appropriate warning at both compile time and run time.