Hi,
I’m trying to set up a data grid on AWS ECS.
I was able to get JCache working with these tutorials:
But session replication is not working. I developed a very simple JSF webapp to test based on the hajspcluster demo, it has on web.xml and the session attributes are serializable.
What am I missing?
Thanks
Session test application code:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<f:view transient="true">
<h:body>
<h:form id="form">
Key <h:inputText value="#{indexBean.key}" />
Value <h:inputText value="#{indexBean.value}" />
<h:commandButton value="add" action="#{indexBean.add()}" />
<br /><br />
<ul>
<li>server: <h:outputText value="#{facesContext.externalContext.request.serverName}" /></li>
<li>session id: <h:outputText value="#{facesContext.externalContext.request.session.id}" /></li>
<li>Served From Server instance: #{indexBean.instanceName}</li>
<li>Executed Server IP Address: #{indexBean.hostAddress}</li>
</ul>
<br /><br />
<ui:repeat id="itens" value="#{indexBean.sessionMap}" var="item">
#{item.key} - #{item.value} <br />
</ui:repeat>
</h:form>
</h:body>
</f:view>
</html>
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSF/JSFManagedBean.java to edit this template
*/
package com.mycompany.session.test;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import java.net.UnknownHostException;
import java.util.Map;
import javax.faces.context.FacesContext;
/**
*
* @author fjaekel
*/
@Named(value = "indexBean")
@SessionScoped
public class IndexBean implements Serializable {
private String key;
private String value;
/**
* Creates a new instance of IndexBean
*/
public IndexBean() {
}
public void add()
{
getSessionMap().put(key, value);
System.out.println(getSessionMap());
}
public String getInstanceName()
{
return System.getProperty("com.sun.aas.instanceName");
}
public String getHostAddress()
{
try {
return java.net.InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException ex) {
return ex.getMessage();
}
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Map<String, Object> getSessionMap() {
return FacesContext.getCurrentInstance().getExternalContext().getSessionMap();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<distributable/>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
<!--<tracking-mode>COOKIE</tracking-mode>-->
</session-config>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<session-config>
<session-manager persistence-type="hazelcast">
<manager-properties>
<property name="relaxCacheVersionSemantics" value="true"/>
</manager-properties>
</session-manager>
</session-config>
</glassfish-web-app>