1 2 Previous Next 15 Replies Latest reply on Jan 21, 2011 3:02 AM by Nicklas Karlsson

    CDI and session replication fails

    Fin Steenbjerg Newbie

      My application uses jsf and cdi on top of jboss 6.0 final. I have deployed it to a jboss cluster consisting of two nodes and an apache server with mod_cluster in front of it. I have attached the xhtml file I am using (it is extremely simple). The cdi bean looks like this

       

      @SessionScoped

      @Named

      public class Pojo implements Serializable {

          private static final Logger logger = LoggerFactory.getLogger(Pojo.class);

       

          private String someField;

       

          public String getSomeField() {

              return someField;

          }

       

          @Override

          public String toString() {

              return "[someField, " + someField + "]";

          }

       

          public void setSomeField(String someField) {

              this.someField = someField;

              logger.info("New field value: '{}'", someField);

          }

       

          @PostConstruct

          public void startup() {

              logger.info("Startup");

          }

       

          @PreDestroy

          public void stop() {

              logger.info("Stop");

          }

      }

       

      Be aware that it is session scoped. The above works fine but it throws an exception in case of a jboss node failover and the request hits the other jboss node. This second node contains the session since I have specified <distributable/> inside the web.xml. The exception thrown is

       

       

      2011-01-14 10:48:36,738 ERROR[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jb.tes.cluster.web]](ajp-127.0.0.1-8209-1) Exception sending request initialized lifecycle event tolistener instance of class org.jboss.weld.servlet.WeldListener:java.lang.NullPointerException

                       atorg.jboss.weld.context.ForwardingContextual.toString(ForwardingContextual.java:52)[:6.0.0.Final]

                       atjava.lang.String.valueOf(String.java:2826) [:1.6.0_23]

                       atjava.lang.StringBuilder.append(StringBuilder.java:115) [:1.6.0_23]

                       atorg.jboss.weld.context.SerializableContextualInstanceImpl.toString(SerializableContextualInstanceImpl.java:67)[:6.0.0.Final]

                       atjava.lang.String.valueOf(String.java:2826) [:1.6.0_23]

                       atjava.lang.StringBuilder.append(StringBuilder.java:115) [:1.6.0_23]

                       atorg.jboss.weld.context.beanstore.AttributeBeanStore.attach(AttributeBeanStore.java:120)[:6.0.0.Final]

                       atorg.jboss.weld.context.AbstractBoundContext.activate(AbstractBoundContext.java:75)[:6.0.0.Final]

                       atorg.jboss.weld.servlet.WeldListener.requestInitialized(WeldListener.java:161)[:6.0.0.Final]

                       atorg.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:180)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)[:6.0.0.Final]

                       atorg.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:593)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.service.session.ClusteredSessionValve.handleRequest(ClusteredSessionValve.java:135)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.service.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:94)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.service.session.JvmRouteValve.invoke(JvmRouteValve.java:88)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.service.session.LockingValve.invoke(LockingValve.java:62)[:6.0.0.Final]

                       atorg.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)[:1.1.0.Final]

                       atorg.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)[:1.1.0.Final]

                       atorg.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)[:6.0.0.Final]

                       atorg.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)[:6.0.0.Final]

                       atorg.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)[:6.0.0.Final]

                       atorg.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)[:6.0.0.Final]

                       atorg.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)[:6.0.0.Final]

                       atorg.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)[:6.0.0.Final]

                       atorg.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:504)[:6.0.0.Final]

                       atorg.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:437)[:6.0.0.Final]

                       atorg.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)[:6.0.0.Final]

                       at java.lang.Thread.run(Thread.java:662) [:1.6.0_23]

       

      BTW I got an servlet filter that logs session attributes. The weld session attributes are:

       

       

      10:42:41,323INFO [dk.jyskebank.cluster.statefulsession.SessionLoggingFilter] Attribute

      'org.jboss.weld.context.http.HttpSessionContext#org.jboss.weld.bean-jboss.classloader:id="vfs:///D:/udvikler/jboss/jboss60-cluster/server/node01/farm/jb.tes.cluster.ear/jb.tes.cluster.web.war/"-ManagedBean-classdk.jyskebank.cluster.statefulsession.Pojo'

      has value :

      Bean: Managed Bean[class dk.jyskebank.cluster.statefulsession.Pojo] with qualifiers [@Any@Default @Named]; Instance: [someField, somevalue]; CreationalContext:org.jboss.weld.context.CreationalContextImpl@100efbb

       

      What am I doing wrong ?

      Has anyone tried using CDI in a cluster environment with session replication ?

        • 1. CDI and session replication fails
          Nicklas Karlsson Master

          NPE:s are always fishy, could you try raising this issue on the seamframework.org Weld forums?

          • 2. CDI and session replication fails
            Nicklas Karlsson Master

            Pete Muir recalled that there might be some related fixes to that in 1.0.0.Final, can you upgrade Weld and test?

            • 3. CDI and session replication fails
              Fin Steenbjerg Newbie

              How do you recommend me to upgrade weld? Should I build JBoss AS and upgrade via maven?

              • 4. CDI and session replication fails
                Nicklas Karlsson Master

                For trunk do a git clone from weld on github.

                Then using the jboss public repo, do mvn install

                Then set JBOSS_HOME and do mvn in jboss-as subdir.

                • 5. CDI and session replication fails
                  Nicklas Karlsson Master

                  You can try 1.0.1.Final first by getting http://sourceforge.net/projects/jboss/files/Weld/1.0.1.Final/weld-1.0.1-Final.zip/download and doing the mvn in jboss-as with your JBOSS_HOME set.

                  • 6. Re: CDI and session replication fails
                    Fin Steenbjerg Newbie

                    We have upgraded weld from the git trunk (hash version: a4f795dadb9c993d727ee933c689cd0e101ab997) and upgraded our jboss AS. In the logs Weld writes:

                     

                    2011-01-17 14:49:19,736 INFO  [org.jboss.weld.Version] (Thread-2) WELD-000900 1.1.0 (2011-01-17 00:00)

                     

                    So it seems like it is using the new version.

                     

                    But it still throws an exception:

                     

                     

                    2011-01-17 15:32:58,618 INFO  [org.jboss.modcluster.ha.HAModClusterService] (AsynchViewChangeHandler Thread) Removing jvm route [node01] from proxy [/127.0.0.1:6666] on behalf of crashed member: 127.0.0.1:1199

                    2011-01-17 15:33:24,445 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/jb.tes.cluster.web]] (ajp-127.0.0.1-8209-1) Exception sending request initialized lifecycle event to listener instance of class org.jboss.weld.servlet.WeldListener: java.lang.IllegalStateException: Error restoring serialized contextual with id org.jboss.weld.bean-jboss.classloader:id="vfs:///D:/udvikler/jboss/jboss60-cluster-test/server/node01/farm/jb.tes.cluster.ear/jb.tes.cluster.web.war/"-ManagedBean-class dk.jyskebank.cluster.statefulsession.Pojo

                        at org.jboss.weld.context.SerializableContextualImpl.loadContextual(SerializableContextualImpl.java:108) [:2011-01-17 00:00]

                        at org.jboss.weld.context.SerializableContextualImpl.get(SerializableContextualImpl.java:91) [:2011-01-17 00:00]

                        at org.jboss.weld.context.SerializableContextualImpl.delegate(SerializableContextualImpl.java:42) [:2011-01-17 00:00]

                        at org.jboss.weld.context.ForwardingContextual.toString(ForwardingContextual.java:52) [:2011-01-17 00:00]

                        at java.lang.String.valueOf(String.java:2826) [:1.6.0_23]

                        at java.lang.StringBuilder.append(StringBuilder.java:115) [:1.6.0_23]

                        at org.jboss.weld.context.SerializableContextualInstanceImpl.toString(SerializableContextualInstanceImpl.java:67) [:2011-01-17 00:00]

                        at java.lang.String.valueOf(String.java:2826) [:1.6.0_23]

                        at java.lang.StringBuilder.append(StringBuilder.java:115) [:1.6.0_23]

                        at org.jboss.weld.context.beanstore.AttributeBeanStore.attach(AttributeBeanStore.java:120) [:2011-01-17 00:00]

                        at org.jboss.weld.context.AbstractBoundContext.activate(AbstractBoundContext.java:75) [:2011-01-17 00:00]

                        at org.jboss.weld.servlet.WeldListener.requestInitialized(WeldListener.java:161) [:2011-01-17 00:00]

                        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:180) [:6.0.0.Final]

                        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.Final]

                        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:593) [:6.0.0.Final]

                        at org.jboss.web.tomcat.service.session.ClusteredSessionValve.handleRequest(ClusteredSessionValve.java:135) [:6.0.0.Final]

                        at org.jboss.web.tomcat.service.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:94) [:6.0.0.Final]

                        at org.jboss.web.tomcat.service.session.JvmRouteValve.invoke(JvmRouteValve.java:88) [:6.0.0.Final]

                        at org.jboss.web.tomcat.service.session.LockingValve.invoke(LockingValve.java:62) [:6.0.0.Final]

                        at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]

                        at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]

                        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.Final]

                        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.0.0.Final]

                        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.Final]

                        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.Final]

                        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.Final]

                        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.Final]

                        at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.Final]

                        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.Final]

                        at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:504) [:6.0.0.Final]

                        at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:437) [:6.0.0.Final]

                        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.Final]

                        at java.lang.Thread.run(Thread.java:662) [:1.6.0_23]

                    • 7. Re: CDI and session replication fails
                      Nicklas Karlsson Master

                      OK, Could you please file a WELD JIRA with the steps to reproduce?

                      • 9. Re: CDI and session replication fails
                        Nicklas Karlsson Master

                        BTW, I tried reproducing this without the apache in front and just changing ports in the browser from 8080 to 8180 mid-flight and I got a similar exception. Is this a reliable way to reproduce or am I cutting too many corners?

                        • 10. Re: CDI and session replication fails
                          Fin Steenbjerg Newbie

                          As long as it is the same http session that you are using for the requests, it should be alright

                          • 11. CDI and session replication fails
                            Nicklas Karlsson Master

                            The port is different so it might be that the session is not considered the same.

                             

                            I tried installing the apache frontend but ran into some n00b-problems: http://community.jboss.org/message/581810#581810 Do you have any insights on this?

                            • 12. CDI and session replication fails
                              Fin Steenbjerg Newbie

                              No haven't seen any problems. We are using apache 2.2.17.

                              • 13. CDI and session replication fails
                                Nicklas Karlsson Master

                                Did you start from a pre-existing Apache or did you download the mod_cluster bundled one?

                                • 14. CDI and session replication fails
                                  Fin Steenbjerg Newbie

                                  We used pre-existing Apache and installed mod_cluster on top of it.

                                  1 2 Previous Next