users@websocket-spec.java.net

[jsr356-users] Websockets in JSR 356 GlassFish 4.0 Embedded Build 7.2 and CDI injection

From: Peter Pilgrim <peter.pilgrim_at_gmail.com>
Date: Thu, 21 Feb 2013 09:45:45 +0000

Hi Everyone on the Websockets User

I am reviewing the WebSockets bundled in the GlassFish 4.0 promoted
build 72. I have successfully got a deployed WAR running in GlassFish
embedded container using Gradle.

Does the WebSockets implementation in this promoted build work
currently against CDI?

I tried the following code:

@ApplicationScoped
class SampleBean {
   @PostConstruct public void init() { System.out.printtf("%s.init()
called\n", getClass().getSimpleName() );
   public getValue() { return "whatever"; }
}

@WebSockedEndpoint( "/test" )
class SampleEndPoint {

     @Inject @ApplicationScoped private SampleBean sampleBean;

     @PostConstruct public void init() { System.out.printtf("%s.init()
called\n", getClass().getSimpleName() );

     @WebSocketMessage
     public String echo(String message) {
        return "ECHO: " + message + " and iCDI njected bean was "+sampleBean;
     }
}

So far, CDI (or the WELD implementation) does not appear to inject any
type of bean, including Application Scoped beans, in to an Endpoint.
Is this a limitation of the current Tyrus reference implementation? Or
is it part of the Web Socket spec?

In fact, I never see SampleBean being initialised at all in the
console output. Strange.


Thanks in advance for your help

Oh yes: There is an empty WEB-INF/beans.xml ;-)

PS: Embedded container code looks similar to this from my blog
http://www.xenonique.co.uk/blog/?p=980 "GlassFish 4 Promoted Build,
Gradle and Embedded Application Server"

-- 
Peter Pilgrim,
**Java Champion**,
Java EE Software Development / Design / Architect for `BlueChip'
enterprises, London, UK
JavaFX ++ Scala ++ Groovy ++  Android ++ Java
:: http://www.xenonique.co.uk/blog/  ::
:: http://twitter.com/peter_pilgrim ::
:: http://java-champions.java.net/ ::