[ 
https://issues.apache.org/jira/browse/TOMEE-947?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13668027#comment-13668027
 ] 

Dimitri commented on TOMEE-947:
-------------------------------

Romain,

Thank you for your detailed explanation. Seems like I've misunderstood CDI 
principles (was trying to inject into an unmanaged bean).

I've tried to make TestInbound a separate class and to inject it into 
TestServlet. Still no luck: if I try to make it @RequestScoped or 
@SessionScoped, I get the following:

SEVERE: Allocate exception for servlet Test
java.lang.VerifyError: class test.TestInbound$$OwbNormalScopeProxy0 overrides 
final method onTextData.(Ljava/io/Reader;)V

Full stacktrace: http://pastebin.com/usvmMQ41

If I make it @Dependent or give it no scope at all, then injection of 
TestInbound into TestServlet works, but I'm still not able to inject 
@RequestScoped or @SessionScoped beans into TestInbound, with the same message 
(WARNING: Could NOT lazily initialize session context because of null 
RequestContext). However, injecting @ApplicationScoped beans does work.

I see that passing session-shared data into WebSocket handlers is rather 
problematic right now. In my current project, I pass the necessary data via 
StreamInbound() constructor, and, if the data was previously injected, I have 
to clone it (in order not to pass an OWB proxy). Are there any recommendations 
on how to do this the right way? Any estimate on when the websocket threading 
is going to be settled?

Thanks!
                
> Injection doesn't work in WebSocket inbound threads
> ---------------------------------------------------
>
>                 Key: TOMEE-947
>                 URL: https://issues.apache.org/jira/browse/TOMEE-947
>             Project: TomEE
>          Issue Type: Bug
>    Affects Versions: 1.6.0
>         Environment: Oracle JDK 1.7.0.21, Linux i586, 
> apache-tomee-1.6.0-20130525.041140-81-jaxrs
>            Reporter: Dimitri
>         Attachments: WebSocket-CDI-Test.war, WebSocket-CDI-Test.zip
>
>
> When using Tomcat's WebSocket implementation (that means, extending 
> org.apache.catalina.websocket.WebSocketServlet), it is not possible to use 
> injection, both CDI and non-CDI, from inbound processing threads. Injecting 
> scoped and non-scoped objects simply gives null.
> Furthermore, when trying to access a session-scoped instance (OWB proxy) that 
> has already been injected into some other object, the following is written to 
> the log:
> May 26, 2013 7:57:49 PM org.apache.openejb.cdi.CdiAppContextsService 
> lazyStartSessionContext
> WARNING: Could NOT lazily initialize session context because of null 
> RequestContext

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to