3 Replies Latest reply on Dec 16, 2014 3:45 AM by jharting

    Weld integration question: HTTP session replication and passivation

    mark.nuttall

      Hello,

      I'm looking for help integrating Weld into an application server runtime that supports HTTP session replication and passivation. I'm specifically trying to get @SessionScoped CDI beans working properly for simple HTTP requests.In my environment, HTTP session attributes are persisted to a database as each ServletRequest is created and destroyed. The problem that I am seeing is that the HTTP session attributes are not being updated on request destruction, causing the session database to become stale. I expect to be able to restart my application server and have @SessionScoped beans reconstituted correctly, but the values read out through AbstractSessionBeanStore.get(BeanIdentifier) are the values as at object creation - not their most recent state. This is because AbstractSessionBeanStore.setAttribute() is only being called once per session in my environment, and not once per request.

       

      My question is, are there integration points in Weld that I must implement in order to get HTTP session replication and passivation working? For example, I can see events being fired within org.jboss.weld.servlet.HttpContextLifecycle.requestDestroyed() - is that something that I should be hooking into? There's nothing in the Weld integrator's guide on this topic so I'm not sure how best to proceed.

       

      Many thanks in advance for any help that anyone can offer me.

       

      Regards,

      Mark

        • 1. Re: Weld integration question: HTTP session replication and passivation
          mkouba

          Hi Mark,

          Weld does not invoke HttpSession.setAttribute() at the end of the request (during ServletRequestListener.requestDestroyed() notification). HttpSession.getAttribute()/setAttribute() is called when the session context is activated (during ServletRequestListener.requestInitialized() notification). HttpSession.setAttribute() is also called when a new bean instance of of a @SessionScoped or @ConversationScoped bean is created. I'm not sure there is some portable way to observe HttpSession.getAttribute() invocation though.

          • 2. Re: Weld integration question: HTTP session replication and passivation
            mark.nuttall

            Hi Martin,

            Thank you for your reply. Let me rephrase the question: does Weld support HTTP session passivation, replication and failover? If so, where is this documented? Many thanks in advance for any help.

             

            Regards,

            Mark

            • 3. Re: Weld integration question: HTTP session replication and passivation
              jharting

              Weld does support replication of @SessionScoped and @ConversationScoped bean instances. It is built on session replication which a Servlet container may or may not provide. As long as an attribute, which is stored in the session by Weld, gets replicated, Weld's instance on the other node of a cluster finds this attribute and will use it. There is nothing more to be configured.

               

              Note that Weld does not re-set the attribute after each change to a bean instance. It is therefore important that the Servlet container replication is triggered by session.getAttribute().