WebSocket and CDI integration.. again..

In one of my older blog posts, I had written about what does not work as far as WebSocket and CDI integration within the Java EE Platform ;-) This one talks about what’s possible with CDI in terms of

  • Dependency Injection
  • Interceptors

Before you dig in, here is a summary

Feature Supported in EJB Annotated WebSocket endpoint ? Supported in Plain WebSocket endpoint ?
Inject CDI managed beans yes yes
Use CDI interceptors yes yes

DI support

It is possible to inject CDI managed beans in WebSocket endpoints. All injection targets are supported i.e. field, constructor, method

 

Interceptor support

You can use interceptors to implement cross-cutting concerns in for the business methods in your WebSocket endpoints

Good to know

Now that you have an idea about how WebSockets work with CDI in terms of Dependency injection and Interceptors, here are some other points

  • DI and interceptors are supported for both server and client endpoints running within a JavaEE container
  • DI and interceptors are supported for both annotated and programatic endpoints running within a JavaEE container
  • container managed injection features are not available to WebSocket endpoints which override the container implemented initialization (using the ServerEndpointConfig.Configurator)

Additional reading

 

Cheers!

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, Java EE and tagged , , , , , , , . Bookmark the permalink.

3 Responses to WebSocket and CDI integration.. again..

  1. Pingback: Java Weekly 103: Garbage collection, CDI 2.0 and productivity

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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