DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Building Better dApps With Infura’s Polygon WebSocket
  • Writing a Chat With Akka
  • Testing WebSocket Endpoints With Firecamp
  • Real-Time Stock Data Updates with WebSockets using Ballerina

Trending

  • How To Aim for High GC Throughput
  • Exploring the Evolution and Impact of Computer Networks
  • The Promise of Personal Data for Better Living
  • Apache Flink
  1. DZone
  2. Coding
  3. Tools
  4. Configuring WebSocket Server Endpoints

Configuring WebSocket Server Endpoints

In this post we take a look at how to configure WebSocket server endpoints in Java EE and their related options. Read on for more details.

Abhishek Gupta user avatar by
Abhishek Gupta
CORE ·
Nov. 06, 16 · Tutorial
Like (3)
Save
Tweet
Share
8.95K Views

Join the DZone community and get the full member experience.

Join For Free

Before we dive into the details, here is a quick snapshot of the related interfaces

Class/InterfaceDescription
ServerEndpointConfigA derivative of EndpointConfig interface which is specific for configuration related to server side WebSocket endpoints
ServerEndpointConfig.ConfiguratorAn interface whose custom implementation allows sharing of global (for all endpoints) available logic/state as well opportunity to intercept the WebSocket handshake process (via method override)
ServerEndpointConfig.BuilderUsed only for programmatic server endpoints to build a ServerEndpointConfig instance

From here on, we’ll explore the configuration strategies for annotated and programmatic server endpoints

Configuring Annotated Server Endpoints

Annotated server endpoints are configured implicitly via the elements of the @ServerEndpoint annotation. The WebSocket container picks up the value from the annotation elements and creates an instance of EndpointConfig behind the scenes. This instance is automatically injected (at run time by the WebSocket container) as a parameter of the @OnOpen method

Configuring Programmatic Server Endpoints

Programmatic endpoints need (explicit) coding as far as configuration is concerned. This is because of the fact that programmatic endpoints are deployed differently and need an instance of ServerEndpointConfig

Please look at this blog post for details of the deployment aspects for programmatic WebSocket endpoints

Here is where the fluent builder ServerEndpointConfig.Builder comes into picture. Let’s look at an example which deomnstrates its usage

The Big Picture

Annotated and programmatic endpoint configuration are handled differently, but the end result is the same. Below is a table which shows the mapping b/w corresponding element of the @ServerEndpoint annotation, the corresponding method in ServerEndpointConfig as well as appropriate the method in the ServerEndpointConfig.Builder

@ServerEndpoint annotation elementServerEndpointConfig methodServerEndpointConfig.Builder method
valuegetPath()create(Class<?> endpointClass, String path)
configuratorgetConfigurator()configurator(ServerEndpointConfig.Configurator serverEndpointConfigurator)
decodersgetDecoders()decoders(List<Class<? extends Decoder>> decoders)
encodersgetEncoders()encoders(List<Class<? extends Encoder>> encoders)
subprotocolsgetSubprotocols()subprotocols(List<String> subprotocols)

Cheers!

WebSocket

Published at DZone with permission of Abhishek Gupta, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building Better dApps With Infura’s Polygon WebSocket
  • Writing a Chat With Akka
  • Testing WebSocket Endpoints With Firecamp
  • Real-Time Stock Data Updates with WebSockets using Ballerina

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: