1 Reply Latest reply on Jul 24, 2013 9:27 AM by renevanwijk

    Session Replication (need to log-in again)

    renevanwijk

      Using JBoss EAP 6.1.0 Alpha (http://www.jboss.org/jbossas/downloads/) - using EAP instead of AS as this will also be our platform in production.

       

      The problem is with session replication and login (actually the session is replicated, but the user must log-in again). The test set-up is as follows

       

      {code}

      package userinterface.servlets;

       

       

      import model.entities.Klant;

      import javax.servlet.ServletException;

      import javax.servlet.http.HttpServlet;

      import javax.servlet.http.HttpServletRequest;

      import javax.servlet.http.HttpServletResponse;

      import javax.servlet.http.HttpSession;

      import java.io.IOException;

      import java.io.PrintWriter;

      import java.util.Enumeration;

      import java.util.Random;

       

       

      public class TestServlet extends HttpServlet {

       

       

          private Random generator;

       

       

          @Override

          public void init() throws ServletException {

              generator = (Random)getServletContext().getAttribute("generator");

          }

       

       

          @Override

          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

              HttpSession session = request.getSession(false);

       

       

              // generate a random client

              Klant klant = createKlant();

       

       

              // insert a client

              session.setAttribute(klant.getKlantnummer().toString(), klant);

              if (generator.nextDouble() < 0.001) {

                  // remove a client

                  session.removeAttribute(generateKlantNummer().toString());

              } else {

                  // find a client by ID

                  session.getAttribute(generateKlantNummer().toString());

              }

       

       

              PrintWriter writer = response.getWriter();

              Enumeration<String> clientids = session.getAttributeNames();

              while (clientids.hasMoreElements()) {

                  writer.println(session.getAttribute(clientids.nextElement()));

              }

              writer.flush();

              writer.close();

          }

       

       

          private Klant createKlant() {

              int klantnummer = generateKlantNummer();

       

       

              Klant klant = new Klant();

              klant.setKlantnummer(klantnummer);

              klant.setNaam("Middleware" + klantnummer);

              klant.setAdres("Magic");

              klant.setStad("Pune");

              klant.setProvincie("IN");

              klant.setPostcode("1234AB");

              klant.setGebied(1);

              klant.setTelefoonnummer("123-4567");

              klant.setReputatieNummer(1);

              klant.setKredietlimiet(Math.rint(generator.nextDouble() * 5000.0));

              klant.setCommentaar(Long.toString(Math.abs(generator.nextLong()), 36));

       

       

              return klant;

          }

       

       

          private Integer generateKlantNummer() {

              return generator.nextInt(10000);

          }

      }

      {code}

       

      in which the 'Klant' object implements the Serializable interface. The deployment descriptor (web.xml) has the following contents:

       

      {code:xml}

      <?xml version="1.0" encoding="UTF-8"?>

      <web-app xmlns="http://java.sun.com/xml/ns/javaee"

                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

                            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

                 version="3.0">

          <distributable/>

          <listener>

              <listener-class>userinterface.listeners.ContextListener</listener-class>

          </listener>

          <servlet>

              <servlet-name>TestServlet</servlet-name>

              <servlet-class>userinterface.servlets.TestServlet</servlet-class>

          </servlet>

          <servlet-mapping>

              <servlet-name>TestServlet</servlet-name>

              <url-pattern>/test</url-pattern>

          </servlet-mapping>

          <security-constraint>

              <web-resource-collection>

                  <web-resource-name>All</web-resource-name>

                  <url-pattern>/test</url-pattern>

              </web-resource-collection>

              <auth-constraint>

                  <role-name>MANAGER</role-name>

                  <role-name>EMPLOYEE</role-name>

              </auth-constraint>

              <user-data-constraint>

                  <transport-guarantee>NONE</transport-guarantee>

              </user-data-constraint>

          </security-constraint>

          <login-config>

              <auth-method>FORM</auth-method>

              <form-login-config>

                  <form-login-page>/login.jsp</form-login-page>

                  <form-error-page>/login.jsp</form-error-page>

              </form-login-config>

          </login-config>

          <security-role>

              <role-name>MANAGER</role-name>

          </security-role>

          <security-role>

              <role-name>EMPLOYEE</role-name>

          </security-role>

      </web-app>

      {code:xml}

       

      The roles are mapped to two different users 'employee' and 'manager'.

       

      The environment consists of two servers on one host. When the servers are started the following is observed in the logging

       

      {code}

      CLUSTER_SERVER1

      12:23:36,621 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 68) ISPN000094: Received new cluster view: [jboss:cluster-server2/web|1] [jboss:cluster-server2/web, jboss:cluster-server1/web]

      12:23:36,671 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 68) ISPN000079: Cache local address is jboss:cluster-server1/web, physical addresses are [192.168.1.150:55200]

      12:23:36,675 INFO  [org.infinispan.factories.GlobalComponentRegistry] (ServerService Thread Pool -- 68) ISPN000128: Infinispan version: Infinispan 'Delirium' 5.2.1.Final

      12:23:36,709 INFO  [org.infinispan.factories.TransactionManagerFactory] (ServerService Thread Pool -- 62) ISPN000161: Using a batchMode transaction manager

      12:23:36,709 INFO  [org.infinispan.factories.TransactionManagerFactory] (ServerService Thread Pool -- 68) ISPN000161: Using a batchMode transaction manager

      12:23:36,849 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 62) ISPN000031: MBeans were successfully registered to the platform MBean server.

      12:23:36,849 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 68) ISPN000031: MBeans were successfully registered to the platform MBean server.

      12:23:36,932 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) JBAS010281: Started repl cache from web container

      12:23:36,933 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 68) JBAS010281: Started default-host/SessionTest cache from web container

      12:23:36,942 INFO  [org.jboss.as.clustering] (MSC service thread 1-1) JBAS010238: Number of cluster members: 2

      12:23:36,950 INFO  [org.jboss.web] (ServerService Thread Pool -- 68) JBAS018210: Register web context: /SessionTest

      12:23:37,086 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "SessionTest.war" (runtime-name : "SessionTest.war")

      12:23:37,091 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.1.0.Alpha1 (AS 7.2.0.Alpha1-redhat-4) started in 9951ms - Started 212 of 334 services (120 services are passive or on-demand)

      12:23:39,290 INFO  [org.jboss.modcluster.ModClusterService] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Engine [jboss.web] will use jvmRoute: 1726e2ea-afe6-3b91-81c9-27be18d761de

       

      CLUSTER_SERVER2

      12:23:35,320 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 62) ISPN000094: Received new cluster view: [jboss:cluster-server2/web|0] [jboss:cluster-server2/web]

      12:23:35,358 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 62) ISPN000079: Cache local address is jboss:cluster-server2/web, physical addresses are [192.168.1.150:55201]

      12:23:35,363 INFO  [org.infinispan.factories.GlobalComponentRegistry] (ServerService Thread Pool -- 62) ISPN000128: Infinispan version: Infinispan 'Delirium' 5.2.1.Final

      12:23:35,399 INFO  [org.infinispan.factories.TransactionManagerFactory] (ServerService Thread Pool -- 67) ISPN000161: Using a batchMode transaction manager

      12:23:35,399 INFO  [org.infinispan.factories.TransactionManagerFactory] (ServerService Thread Pool -- 62) ISPN000161: Using a batchMode transaction manager

      12:23:35,556 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 67) ISPN000031: MBeans were successfully registered to the platform MBean server.

      12:23:35,557 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 62) ISPN000031: MBeans were successfully registered to the platform MBean server.

      12:23:35,572 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 67) JBAS010281: Started default-host/SessionTest cache from web container

      12:23:35,572 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) JBAS010281: Started repl cache from web container

      12:23:35,582 INFO  [org.jboss.as.clustering] (MSC service thread 1-5) JBAS010238: Number of cluster members: 1

      12:23:35,591 INFO  [org.jboss.web] (ServerService Thread Pool -- 67) JBAS018210: Register web context: /SessionTest

      12:23:35,732 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "SessionTest.war" (runtime-name : "SessionTest.war")

      12:23:35,738 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.1.0.Alpha1 (AS 7.2.0.Alpha1-redhat-4) started in 7162ms - Started 212 of 334 services (120 services are passive or on-demand)

      12:23:36,594 INFO  [org.jboss.as.clustering] (Incoming-1,shared=udp) JBAS010225: New cluster view for partition web (id: 1, delta: 1, merge: false) : [jboss:cluster-server2/web, jboss:cluster-server1/web]

      12:23:36,597 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (Incoming-1,shared=udp) ISPN000094: Received new cluster view: [jboss:cluster-server2/web|1] [jboss:cluster-server2/web, jboss:cluster-server1/web]

      12:23:41,748 INFO  [org.jboss.modcluster.ModClusterService] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Engine [jboss.web] will use jvmRoute: 65c20051-14de-33f1-9c6a-496622a06602

      {code}

       

      Next, the application is accessed on two different browsers (chrome and firefox) by two different users. When looking in the mod_cluster_manager the following is observed:

       

      {code}

      mod_cluster/1.2.0.Final

      start of "httpd.conf" configuration

      mod_proxy_cluster.c: OK

      mod_sharedmem.c: OK

      Protocol supported: http AJP

      mod_advertise.c: OK

      Server: middleware-magic.com

      Server: middleware-magic.com VirtualHost: middleware-magic.com:8888 Advertising on Group 224.0.1.105 Port 23364 for http://192.168.1.150:8888 every 10 seconds

      end of "httpd.conf" configuration

       

      Auto Refresh show DUMP output show INFO output

      Node 1726e2ea-afe6-3b91-81c9-27be18d761de (ajp://192.168.1.150:8009):

      Enable Contexts Disable Contexts

      Balancer: mycluster,LBGroup: ,Flushpackets: Off,Flushwait: 10000,Ping: 10000000,Smax: 1,Ttl: 60000000,Status: OK,Elected: 49,Read: 14422,Transferred: 107,Connected: 0,Load: 100

      Virtual Host 1:

      Contexts:

       

      /SessionTest, Status: ENABLED Request: 0 Disable

       

      Aliases:

      default-host

      localhost

      example.com

       

       

      Node 65c20051-14de-33f1-9c6a-496622a06602 (ajp://192.168.1.150:8010):

      Enable Contexts Disable Contexts

      Balancer: mycluster,LBGroup: ,Flushpackets: Off,Flushwait: 10000,Ping: 10000000,Smax: 1,Ttl: 60000000,Status: OK,Elected: 0,Read: 0,Transferred: 0,Connected: 0,Load: 100

      Virtual Host 1:

      Contexts:

       

      /SessionTest, Status: ENABLED Request: 0 Disable

       

      Aliases:

      default-host

      localhost

      example.com

      {code}

       

      Next, we shutdown the server on which the requests have been coming in (funny thing as well, as two different users have logged in from two different hosts, the users seem to have come to only one server. This is observed from the request count metric of the Web subsystem). After the server has been shutdown the following is observed in the logging:

       

      {code}

      CLUSTER-SERVER1

      12:47:06,900 INFO  [org.apache.coyote.http11] (MSC service thread 1-2) JBWEB003075: Coyote HTTP/1.1 pausing on: http-/192.168.1.150:8080

      12:47:06,908 INFO  [org.apache.coyote.http11] (MSC service thread 1-2) JBWEB003077: Coyote HTTP/1.1 stopping on : http-/192.168.1.150:8080

      ...

      12:47:06,913 INFO  [org.jboss.modcluster.ModClusterService] (ServerService Thread Pool -- 73) All active sessions drained from context [/SessionTest] in 0 seconds

      ...

      12:47:06,985 INFO  [org.jboss.as.clustering.infinispan] (MSC service thread 1-6) JBAS010282: Stopped default-host/SessionTest cache from web container

      12:47:07,006 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment SessionTest.war (runtime-name: SessionTest.war) in 110ms

      12:47:07,009 INFO  [org.jboss.as.clustering.infinispan] (MSC service thread 1-8) JBAS010282: Stopped repl cache from web container

      12:47:07,012 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (MSC service thread 1-8) ISPN000080: Disconnecting and closing JGroups Channel

      12:47:07,409 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (MSC service thread 1-8) ISPN000082: Stopping the RpcDispatcher

      12:47:07,423 INFO  [org.jboss.as] (MSC service thread 1-8) JBAS015950: JBoss EAP 6.1.0.Alpha1 (AS 7.2.0.Alpha1-redhat-4) stopped in 490ms

       

      CLUSTER-SERVER2

      12:47:07,379 INFO  [org.jboss.as.clustering] (Incoming-11,shared=udp) JBAS010225: New cluster view for partition web (id: 2, delta: -1, merge: false) : [jboss:cluster-server2/web]

      12:47:07,381 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (Incoming-11,shared=udp) ISPN000094: Received new cluster view: [jboss:cluster-server2/web|2] [jboss:cluster-server2/web]

      {code}

       

      When the users resume their requests, they first have to log-in, after the which the session is available in the state it was before the server shutdown. Are there extra steps necessary, such that the users do not have to log-in again?

      Also you would assume the load balancer to work as well, i.e., when one user log-in it is directed to server1, when another logs-in it is directed to server2. Could someone shed a light on this?