In OWB we try to not create any HttpSession if we do not need it. The reason is that we do not like to pollute the Session for e.g. resource or JAXRS requests. That would just blow up the memory.
Instead we create the Session lazily. See WebContextsService#lazyStartSessionContext(boolean createSession).
The ConversationContext and thus the Session gets started whenever you use a @SessionScoped or @ConversationScoped bean the first time and there was no Session yet.
If that is the case AFTER there was some HttpServletResponse written back to the client. then you will get the following Exception:
IllegalStateException: Cannot create a session after the response has been committed.
We might prevent this by starting the Session for every request. But this has quite a few downsides, including slowing down any request and polluting memory with useless Sessions.
A possible solution would be to introduce an eagerSessionInitialisation config entry via openwebbeans.properties. It could have 3 options
- true will create a Session on each request start
- false (should be default) will use lazySessionInit as always
- a custom String which is a regexp for requests which need an eagerly initialized Session. All other requests will use lazySessionInit.
Any comment and further ideas are welcome.