1 of 1 people found this helpful
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.
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?
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.
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?
No idea... please post the code snippet and resulting log msg so that we could check it.