Java Websocket containers: the possibilities

The Java Websocket API (JSR 356) specification supports different containers

  • Good old Java EE 7 app servers – since Websocket API is integrated directly into the Java EE 7 Platform
  • Servlet 3.1 containers
  • Standalone containers – for runtimes which are not servlet complaint

Hello Tyrus !

Tyrus is the reference implementation for Java Websocket API

  • What’s important to understand is that it’s the implementation of the Websocket specification i.e. it provides both Server and Client side support for building Websocket applications using the standard JSR 356 APIs
  • It’s not an out-of-the-box container i.e. does not have a runtime as such

So, how does Tyrus support the above mentioned runtimes ?

Here is how

  • Tyrus has a modular architecture i.e. it has different modules for server, client implementations, a SPI etc.
  • It has the concepts of containers (you can think of them as connectors) for specific runtime support (these build on the modular setup)

Tyrus containers

Servlet container a.k.a tyrus-container-servlet

  • Used to integrate with existing Servlet 3.1 containers
  • Leveraged to plug into the Web (Servlet) Container in Java EE 7 compliant app servers

Standalone container

You have two options

Grizzly Container (tyrus-container-grizzly module)

  • This is achieved with Grizzly (which provides the runtime)
  • Can be used for server or client (or both) modes as per your requirements

Here are the Maven dependencies

Here is the Websocket (annotated) endpoint

Here is how to start it (embedded)

Pure JDK container (tyrus-container-jdk-client module)

  • Client only mode
  • Vanilla JDK i.e. no additional dependencies
  • Leverages JDK 1.7 non-blocking I/O (Asynchronous Channel)

Maven dependencies

The (annotated) client endpoint

Client code to connect to Websocket endpoint (outlined above)



About Abhishek

Currently working as a Senior Product Manager in the Oracle Cloud Application Development team with a focus on Oracle Cloud PaaS portfolio. When not hovering in the clouds, I stay grounded with Java EE
This entry was posted in Java EE and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s