I have removed the load on startup, still it doesn't work.

At the moment, I have my code that is working without CDI due to this
issue. Is not the best but for now it can stay as it is.
I might give a try to the workaround you proposed or I'll wait for the next
release then.


On Tue, Sep 25, 2012 at 4:58 PM, Romain Manni-Bucau
<[email protected]>wrote:

> CDI + Ear still needs a big rework so i'm not totally surprised
>
> Even wonder is removing load on startup would be enough to make it working.
>
> A workaround is actually to use the whole tomee as the ear and put common
> libs in the shared classloader. That's not perfect but ear support of CDI
> is comming (i hope next spec version will handle that correctly since today
> it doesn't answer properly to it).
>
> Not sure we can hack on it before the releas, i fear it can break too much
> things and make us late for the release. I'd prefer to put it as a target
> for next release.
>
> *Romain Manni-Bucau*
> *Twitter: @rmannibucau*
> *Blog: **http://rmannibucau.wordpress.com/*<
> http://rmannibucau.wordpress.com/>
> *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
>
>
>
>
> 2012/9/25 Luca Merolla <[email protected]>
>
> > Yes, I moved the war under webapps and there the injection works. also
> the
> > exception on deployment is gone.
> >
> >
> > On Tue, Sep 25, 2012 at 4:44 PM, Romain Manni-Bucau
> > <[email protected]>wrote:
> >
> > > hmm,
> > >
> > > can you test in a simple war please (== not an ear)?
> > >
> > > *Romain Manni-Bucau*
> > > *Twitter: @rmannibucau*
> > > *Blog: **http://rmannibucau.wordpress.com/*<
> > > http://rmannibucau.wordpress.com/>
> > > *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> > >
> > >
> > >
> > >
> > > 2012/9/25 Luca Merolla <[email protected]>
> > >
> > > > Here is the sample:
> > > >
> > > > *
> > > >
> > > >
> > >
> >
> http://www.fileconvoy.com/dfl.php?id=g9c64757621dc468115011126f019deb361277a
> > > > *
> > > > *
> > > > *
> > > > Deployed under apps/Test.ear it should give the following errors:
> > > >
> > > > On Deployment I get this exception: which however I have already
> > noticed
> > > in
> > > > other web app, but it doesn't seems to effect the CDI injection later
> > > when
> > > > the app is running. In the other web app I get similar exception but
> > it's
> > > > only on deployment and then the @Inject works.
> > > >
> > > > http://pastebin.com/qvqn3WsD
> > > >
> > > > After deployment, If I try to establish the websocket connection and
> I
> > > get:
> > > >
> > > > Sep 25, 2012 4:36:42 PM
> > > > org.pokernuvola.galaxy.gametable.WebSocketGametableServlet
> > > > createWebSocketInbound
> > > > INFO: CREATE connection...FAIL
> > > > Sep 25, 2012 4:36:42 PM
> > > > org.pokernuvola.galaxy.gametable.GametableMessageInbound onOpen
> > > > INFO: Opening the connection |1|
> > > > Sep 25, 2012 4:36:42 PM
> > > > org.pokernuvola.galaxy.gametable.WebSocketGametableServlet
> > > > addGametableConnection
> > > > INFO: add connection...FAIL
> > > > Sep 25, 2012 4:36:52 PM
> > > > org.pokernuvola.galaxy.gametable.GametableMessageInbound
> onTextMessage
> > > > INFO: Got a message text! |Ping|
> > > > Sep 25, 2012 4:36:52 PM
> > > > org.apache.coyote.AbstractProtocol$AbstractConnectionHandler process
> > > > SEVERE: Error reading request, ignored
> > > > java.lang.NullPointerException
> > > >         at
> > > >
> > > >
> > >
> >
> org.pokernuvola.galaxy.gametable.WebSocketGametableServlet.processTextCommand(WebSocketGametableServlet.java:74)
> > > >         at
> > > >
> > > >
> > >
> >
> org.pokernuvola.galaxy.gametable.GametableMessageInbound.onTextMessage(GametableMessageInbound.java:35)
> > > >         at
> > > >
> > > >
> > >
> >
> org.apache.catalina.websocket.MessageInbound.onTextData(MessageInbound.java:74)
> > > >         at
> > > >
> > > >
> > >
> >
> org.apache.catalina.websocket.StreamInbound.doOnTextData(StreamInbound.java:186)
> > > >         at
> > > >
> > >
> >
> org.apache.catalina.websocket.StreamInbound.onData(StreamInbound.java:134)
> > > >         at
> > > >
> > > >
> > >
> >
> org.apache.coyote.http11.upgrade.UpgradeProcessor.upgradeDispatch(UpgradeProcessor.java:83)
> > > >         at
> > > >
> > > >
> > >
> >
> org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:583)
> > > >         at
> > > >
> > > >
> > >
> >
> org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
> > > >         at
> > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
> > > >         at
> > > >
> > > >
> > >
> >
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
> > > >         at java.lang.Thread.run(Thread.java:662)
> > > >
> > > >
> > > >
> > > > On Tue, Sep 25, 2012 at 3:43 PM, Romain Manni-Bucau
> > > > <[email protected]>wrote:
> > > >
> > > > > can you share the sample please?
> > > > >
> > > > > *Romain Manni-Bucau*
> > > > > *Twitter: @rmannibucau*
> > > > > *Blog: **http://rmannibucau.wordpress.com/*<
> > > > > http://rmannibucau.wordpress.com/>
> > > > > *LinkedIn: **http://fr.linkedin.com/in/rmannibucau*
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > 2012/9/25 Luca Merolla <[email protected]>
> > > > >
> > > > > > Hi everyone,
> > > > > >
> > > > > > I have noticed this blog entry
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> http://rmannibucau.wordpress.com/2012/05/15/tomee-or-how-to-use-websocket-with-cdi/
> > > > > > and
> > > > > > I have compared to my solution which is very similar but on my
> case
> > > > since
> > > > > > CDI was not working I had to put some code in the init() method
> of
> > my
> > > > > > servlet to retrieve the Beans, like this:
> > > > > >
> > > > > > jsonProvider = (JsonProviderBean)
> getServletContext().getAttribute(
> > > > > > GalaxyConstants.JSON_PROVIDER_BEAN);
> > > > > > processor =
> WebSocketConnectionProcessor.getInstance(jsonProvider);
> > > > > >
> > > > > > the jsonProvider was created in my ServletContextListener class
> and
> > > the
> > > > > > servlet was simply retrieving it. For the
> > > WebSocketConnectionProcessor
> > > > I
> > > > > > opted to make the class singleton and in this way it was working.
> > > > > >
> > > > > > Despite this solution, I have tried to follow the example from
> the
> > > blog
> > > > > of
> > > > > > Romain because I would like to inject the processor.
> > > > > >
> > > > > > @WebServlet(urlPatterns = "/gametable", asyncSupported = true,
> > > > > > loadOnStartup = 1)
> > > > > > public class WebSocketGametableServlet extends WebSocketServlet
> > > > > implements
> > > > > > IWebSocketServlet {
> > > > > >
> > > > > > private static final long serialVersionUID =
> -6573757123424131706L;
> > > > > >
> > > > > > protected final Logger LOGGER =
> LoggerFactory.getLogger(getClass()
> > > > > > .getName());
> > > > > >
> > > > > > @Inject
> > > > > > private WebSocketGametableProcessor processor;
> > > > > > private JsonProviderBean jsonProvider;
> > > > > >
> > > > > > public void init() throws ServletException {
> > > > > > LOGGER.info("Initialize Lobby WebSocket servlet");
> > > > > > super.init();
> > > > > >
> > > > > > initializeWebSocketProcessor();
> > > > > > LOGGER.info("Web Socket connection processor initialized");
> > > > > > }
> > > > > >
> > > > > > /**
> > > > > >  * Get the JSON provider bean from the servlet context and
> retrieve
> > > the
> > > > > >  * {@link WebSocketGametableProcessor} instance
> > > > > >  */
> > > > > > private void initializeWebSocketProcessor() {
> > > > > > LOGGER.info("Getting the json provider bean");
> > > > > > jsonProvider = (JsonProviderBean)
> getServletContext().getAttribute(
> > > > > > GalaxyConstants.JSON_PROVIDER_BEAN);
> > > > > >
> > > > > > // LOGGER.info("Getting the websocker processor instance");
> > > > > > // processor =
> > WebSocketGametableProcessor.getInstance(jsonProvider);
> > > > > > }
> > > > > >
> > > > > > /*
> > > > > >  * (non-Javadoc)
> > > > > >  *
> > > > > >  * @see
> > > > > >  *
> > > > org.apache.catalina.websocket.WebSocketServlet#createWebSocketInbound
> > > > > >  * (java.lang.String, javax.servlet.http.HttpServletRequest)
> > > > > >  */
> > > > > > @Override
> > > > > > protected StreamInbound createWebSocketInbound(String arg0,
> > > > > > HttpServletRequest request) {
> > > > > > return new GametableMessageInbound(this,
> > > > > > (Long) request.getAttribute(WebSocketConstants.SESSION_ID));
> > > > > > }
> > > > > >
> > > > > > @Override
> > > > > > public void addConnection(LobbyKey lobbyKey,
> > > > > > AbstractMessageInbound lobbyConnection) {
> > > > > > if (processor == null)
> > > > > > LOGGER.info("add connection...FAIL");
> > > > > > else
> > > > > > LOGGER.info("add connection...");
> > > > > > }
> > > > > >
> > > > > > @Override
> > > > > > public void removeConnection(LobbyKey lobbyKey,
> > > > > > AbstractMessageInbound lobbyConnection) {
> > > > > > if (processor == null)
> > > > > > LOGGER.info("remove connection...FAIL");
> > > > > > else
> > > > > > LOGGER.info("remove connection...");
> > > > > > }
> > > > > >
> > > > > > @Override
> > > > > > public void processTextCommand(String jsonCommand) {
> > > > > > processor.processWebsocketCommand(jsonCommand);
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > The WebSocketGametableProcessor has no other dependencies
> > > > > >
> > > > > > public class WebSocketGametableProcessor {
> > > > > >
> > > > > > private static final Logger LOGGER = LoggerFactory
> > > > > > .getLogger(WebSocketGametableProcessor.class);
> > > > > >
> > > > > > private WebSocketGametableProcessor() {
> > > > > >
> > > > > > }
> > > > > >
> > > > > > public void processWebsocketCommand(String jsonCommand) {
> > > > > > LOGGER.info("Received json command |{}|", jsonCommand);
> > > > > > }
> > > > > > }
> > > > > >
> > > > > > And as result I have that the WebSocketGametableProcessor is null
> > in
> > > > the
> > > > > > servlet. I was using the snapshot from last week, I have just run
> > the
> > > > > > latest 1.5.1-SNAPSHOT and the issue persist.
> > > > > >
> > > > > > Luca
> > > > > >
> > > > >
> > > >
> > >
>

Reply via email to