View Full Version : Create SessionScope outside of servlets session

05-25-2010, 03:29 PM
Good day

I have a delicate problem - I'm trying to use RWT (http://eclipse.org/rap) as a user interface for an Ajax web application. The problem with RWT is that it runs its user interface thread in a separate thread than the servlet's session thread. This causes Resit to throw the following error when I try to inject SessionScoped services:

javax.enterprise.context.ContextNotActiveException : '@javax.enterprise.context.SessionScoped' is not an active Java Injection context.
at com.caucho.config.inject.InjectManager.getContext( InjectManager.java:1939)
at alchemy.rwt.AlchemyEntryPoint.createUI(AlchemyEntr yPoint.java:33)
at org.eclipse.rwt.internal.lifecycle.EntryPointManag er.createUI(EntryPointManager.java:92)
at org.eclipse.rwt.internal.lifecycle.RWTLifeCycle.cr eateUI(RWTLifeCycle.java:244)

Is there some way that I can activate a session scope for a different thread than the servlet's session thread?

05-25-2010, 04:55 PM
That's an interesting issue. It's not currently possible, but I've added a bug report at http://bugs.caucho.com/view.php?id=4049.

We'd need to add a Resin-specific API to make this work.

It would also be possible to create a custom scope with the behavior that you're looking for, like we did for @TransactionScoped, although I think the extra @SessionScoped behavior would fit your scenario better.

05-26-2010, 04:13 AM
Thanks, this being Resin specific is not a big problem for me. I think the ability to use "standard" context types in my application is more important than perhaps a couple of lines of Resin specific code.

An alternative might be to disable the standard session context that comes with Resin for a given web application. I have developed an SPI extension that implements a custom session context using the built-in SessionScope annotation, but which can be started in any thread. This works in Resin 4.0.6 as long as the custom session context does not run in the same thread as the servlet session. In Resin 4.0.7, however, the CDI engine discovers that there are 2 concurrent SessionScoped contexts running and throws an error (which is correct according to the CDI spec, but not good for my app :))