Async HTTP Client 1.7.0 Released. Details on the Grizzly Side of Things…

Unfortunately, this blog entry is lagging behind in terms of when the release occurred. Earlier this month (1/11), Jean-Francois released Async HTTP Client 1.7.0.

Quoting his release annoucement:

This release is our first with the Grizzly 2 provider, which supports
the same set of features as Netty (and performance wise match Netty
without any problems). This release also contains our first drop of the
WebSocket support (both Netty and Grizzly).

In a previous blog entry I offered some brief examples on using the AHC with the Grizzly provider. This entry also included some maven coordinates for a bundle containing only Grizzly dependencies.
These coordinates have changed. For those interested in this bundle, use the following maven coordinates instead:

Note that we’ll only be maintaining this bundle until such time that the Sonatype Async HTTP Client project modularizes the api and providers into distinct bundles.

With that out of the way, the other new feature available is WebSockets support. Let’s review the moving parts.

The UpgradeHandler

The UpgradeHandler is a general handler/contract for any type of HTTP upgrade request. For WebSockets, there is a concrete implementation called WebSocketUpgradeHandler. Knowledge of the underlying workings of this handler aren’t really necessary. All that you need to remember is that this handler must be passed to the AsyncHttpClient.execute() method. Instances of this handler are created using its associated builder, WebSocketUpgradeHandler.Builder which defines methods that allows the developer to add/remove listeners and perform WebSocket customization:

The behavior properties should be self-explanatory, we’ll touch on WebSocketListeners next.

The WebSocketListener

WebSocketListener is the base interface for all WebSocketListener implementations.

From there, AHC separates listener functionality into text, binary, ping, and pong listeners.

For developer convenience, we’ve added DefaultWebSocketListener that implements all interfaces where all methods (except onOpen/onClosed) are no-ops allowing behavior override only as needed.

The WebSocket

The final interface of interest is WebSocket.

So, a simple example putting all the parts together might look something like:

Final Notes

The Grizzly provider implements the final version of the WebSockets RFC. However, at this point in time, the client will not try to fall back to older versions of the protocol if the server doesn’t support the same version as the client. This is something I hope we can resolve in the next release.

This entry was posted in Java and tagged , , . Bookmark the permalink.

Comments are closed.