-
1. Re: Injecting a session scope bean in to a HttpSessionListener?
mkouba Nov 26, 2012 4:04 AM (in response to troup)1 of 1 people found this helpfulHi Tim,
I think your code should work (injecting proxy of @SessionScoped bean into a servlet listener), except the invalid usage of javax.enterprise.inject.Instance (you must either use sessionStore.get().setSessionId() or inject SessionStore directly and I would prefer the latter). Actually it works for me on JBoss AS7 and Weld 1.1.5, 1.1.8 and 2.0.0.Aplha4. So it looks like a GF issue. It's hard to guess what "Should never reach here" means
BTW CDI 1.1 will provide HttpSession built-in bean to inject.
-
2. Re: Injecting a session scope bean in to a HttpSessionListener?
troup Nov 26, 2012 4:21 AM (in response to mkouba)Hi Martin,
I had assumed that there would only ever be one instance of the HttpSessionListener created by the container and if so the SessionStore object would be injected only once. If this is correct then the session id of the person who uses that app first would be used for everyone. That is why I thought I should be using Instance<> as this dynamically obtains the instance each time?
I take it I misunderstood the lifecycle of HttpSessionListeners? Or injection? Or both?
Thanks, Tim
-
3. Re: Injecting a session scope bean in to a HttpSessionListener?
mkouba Nov 26, 2012 4:32 AM (in response to troup)There is only one instance of the HttpSessionListener I think. However for normal-scoped beans a proxy is injected instead of a direct reference to a bean instance (see also CDI spec, 5.4. "Client proxies"). The client proxy forwards invocations to the actual instance and that's why it's legal to inject e.g. a request scoped bean into a session scoped bean.
-
4. Re: Injecting a session scope bean in to a HttpSessionListener?
troup Nov 26, 2012 4:47 AM (in response to mkouba)Thanks for clarifying that for me.
I see my SessionStore object being populated as I had hoped when a user accesses my app.
However, when my interceptor logs the session id it is always null.
Any ideas why?
-
5. Re: Injecting a session scope bean in to a HttpSessionListener?
mkouba Nov 26, 2012 5:25 AM (in response to troup)No idea... please post the code snippet and resulting log msg so that we could check it.