3 Replies Latest reply on Sep 3, 2017 1:16 PM by art-isan

    Session replication - Widlfly 10 / JBoss EAP 7

    art-isan

      Hi guys,

       

      I have an issue for infinispan session storage. Infinispan doesn't handle session storage in my basic configuration.

      I'm using the default standalone.xml configuration of JBoss EAP 7.0 :

       

      Here is the part from standalone.xml for infinispan :

      <subsystem xmlns="urn:jboss:domain:infinispan:4.0">
         <cache-container name="server" default-cache="default" module="org.wildfly.clustering.server">
         <local-cache name="default">
         <transaction mode="BATCH"/>
         </local-cache>
         </cache-container>
         <cache-container name="web" default-cache="passivation" module="org.wildfly.clustering.web.infinispan">
         <local-cache name="passivation">
         <locking isolation="REPEATABLE_READ"/>
         <transaction mode="BATCH"/>
         <file-store passivation="true" purge="false"/>
         </local-cache>
         <local-cache name="persistent">
         <locking isolation="REPEATABLE_READ"/>
         <transaction mode="BATCH"/>
         <file-store passivation="false" purge="false"/>
         </local-cache>
         </cache-container>
         <cache-container name="ejb" aliases="sfsb" default-cache="passivation" module="org.wildfly.clustering.ejb.infinispan">
         <local-cache name="passivation">
         <locking isolation="REPEATABLE_READ"/>
         <transaction mode="BATCH"/>
         <file-store passivation="true" purge="false"/>
         </local-cache>
         <local-cache name="persistent">
         <locking isolation="REPEATABLE_READ"/>
         <transaction mode="BATCH"/>
         <file-store passivation="false" purge="false"/>
         </local-cache>
         </cache-container>
         <cache-container name="hibernate" default-cache="local-query" module="org.hibernate.infinispan">
         <local-cache name="entity">
         <transaction mode="NON_XA"/>
         <eviction strategy="LRU" max-entries="10000"/>
         <expiration max-idle="100000"/>
         </local-cache>
         <local-cache name="local-query">
         <eviction strategy="LRU" max-entries="10000"/>
         <expiration max-idle="100000"/>
         </local-cache>
         <local-cache name="timestamps"/>
         </cache-container>
      </subsystem>
      

       

      My web.xml :

      <!DOCTYPE web-app PUBLIC
      "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
      "http://java.sun.com/dtd/web-app_2_3.dtd" >
      
      
      <web-app>
        <display-name>Archetype Created Web Application</display-name>
         <distributable/>
      </web-app>
      
      
      

       

      My jsp to put a new attribute to session :

      <html>
      <body>
      <h2>Set Current Time</h2>
      <%
        System.out.println( "Putting date now" );
        session.setAttribute("current.time", new java.util.Date());
      %>
      The time is set to <%= session.getAttribute("current.time") %>
      </body>
      </html>
      

      And the one to get it :

      <html>
      <body>
      <h2>Get Time</h2>
      <%@ page import="com.sample.PageBean"%>
      <%
        System.out.println( "Getting date now" );
        PageBean pb = new PageBean();
      %>
      The time is <%= session.getAttribute("current.time") %>
      <br /><%= pb.getCacheSize() %>
      <br /><%= pb.getCacheContent() %>
      </body>
      </html>
      

      Finally, here is the bean to get infinispan web cache size and content :

      package com.sample;
      
      import org.infinispan.Cache;
      import org.infinispan.manager.EmbeddedCacheManager;
      
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class PageBean {
      
        Cache<String, String> cache;
      
         public PageBean() throws NamingException {
        Context context = new InitialContext();
        EmbeddedCacheManager container = (EmbeddedCacheManager) context.lookup("java:jboss/infinispan/container/web");
         cache = container.getCache();
         cache.clear();
        }
      
         public int getCacheSize(){
         return cache.size();
        }
      
         public String getCacheContent(){
        StringBuffer sb = new StringBuffer();
         cache.entrySet().stream().forEach(cs -> sb.append("key: " + cs.getKey() + ", value: " + cs.getValue() + "<br />"));
         return sb.toString();
        }
      }
      

       

       

      Is threre any configuration missing?

       

      Thank you for your help.

       

      Regards