Programmatic Websocket endpoints in Java EE 7…

This post briefly demonstrates how to develop and deploy (server and client) Websocket endpoints using the programmatic version of the Java Websocket API

To begin with…

extend the javax.websocket.Endpoint class

Let’s code the client endpoint as well (using the same set of APIs)

.. and then

implement the ServerApplicationConfig interface

It is part of the javax.websocket.server package and can be overridden to implement custom logic for endpoint deployment (for both annotated as well as programmatic endpoints)

What about the client endpoint ?

If required, you can create a your own instance of ClientEndpointConfig and use it while initiating a connection to the websocket server endpoint

To be noted

  • Both the client as well as server endpoint config objects are nothing but object (programmatic) equivalents of the elements (value, encoders, decoders, configurator etc.) of the @ServerEndpoint and @ClientEndpoint annotations
  • Separate builder classes (ServerEndpointConfig.Builder and ClientEndpointConfig.Builder) were used to create server and client configuration instances respectively
  • The creation of a ServerEndpointConfig instance is mandatory since server endpoints cannot be deployed without a URI. This is not the case with client endpoints though – all they do is connect to an existing server endpoint.
  • The endpoint config (server & client) have the notion of a configurator which can be created and set via the respective builder methods.

Stay tuned for some more Websocket related action in the near future

feel free to…


About Abhishek

Loves Go, NoSQL DBs and messaging systems
This entry was posted in Java EE and tagged , , . Bookmark the permalink.

2 Responses to Programmatic Websocket endpoints in Java EE 7…

  1. Pingback: Deploying WebSocket annotated & programmatic server endpoints together | Thinking in Java EE (at least trying to!)

  2. Pingback: Configuring WebSocket server endpoints | Thinking in Java EE (at least trying to!)

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s