users@websocket-spec.java.net

[jsr356-users] [jsr356-experts] EJB and CDI Integration

From: Danny Coward <danny.coward_at_oracle.com>
Date: Thu, 24 Jan 2013 12:09:13 -0800

Hi folks,

We have had much discussion about websocket endpoints and other Java EE
components in the last couple of weeks with the EE specification leads,
Linda and Bill. Those of you who are working on a websocket
implementation in Java EE will care about this, those of you who don't
probably won't.

Currently the specification says you can annotate certain EJBs and CDI
managed beans as websocket endpoints, and we have been looking into the
feasibility of this. The goal was to allow developers who use those
models to use some of the services provided by the EJB and CDI
containers in their websocket endpoints.

However, we found that some of the limitations of the EJB and CDI models
don't currently fit well to the websocket endpoint model. In particular,
singleton EJBs, without further annotation have all their requests
serialized, and stateful session beans that throw runtime exceptions are
immediately removed from service. For a CDI managed bean to be a
websocket endpoint, we would really need to define a custom scope to
match the connection lifecycle. All these issues could be resolved, but
we don't feel its worth doing for this version - we may come back to
this for the next version.

However, something that is important is that when websocket endpoints
are running in a full Java EE container, developers should be able to
inject other EE components into them: like EJBs, database connections,
arbitrary CDI managed beans. The official term for this is that
websocket endpoints would be 'non-contextual managed beans'. This is a
central part of the EE programming model, and other web components, like
servlets and JSF components already support this in Java EE. I think we
should too.

Fortunately, the CDI framework makes it easy to provide this
'injectability': provided the endpoint instances are created using the
standard CDI SPI, you get it for free. The websocket implementation, as
soon as the endpoint instance is created, manages everything else as usual.

So I'd like to reduce the requirements on websocket containers that are
part of a full Java EE platform implementation: Change the requirement
that certain EJBs and CDI managed beans can be websocket endpoints
themselves and instead require that Java EE implementations support the
injectability of other Java EE components.

Let me know if you have concerns about this approach.

Thanks !

- Danny
-- 
<http://www.oracle.com> 	*Danny Coward *
Java EE
Oracle Corporation