0
  1. I developing one project using those techs:
    a) Container: Glashfish;
    b) Spring Security;
    c) Java Server Faces;
    d) MySQL.

  2. Used code:

@WebListener public class HazelcastInitializer implements ServletContextListener {

private HazelcastInstance instance;

@Override
public void contextInitialized(ServletContextEvent sce) {
    String sessionMapName = "spring:session:sessions";
    ServletContext sc = sce.getServletContext();

    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getGroupConfig().setName("value").setPassword("value-pass");
    clientConfig.getNetworkConfig().addAddress("ip");
    clientConfig.getNetworkConfig().setSmartRouting(true);

    Collection<SerializerConfig> scfg = new ArrayList<SerializerConfig>();
    SerializerConfig serializer = new SerializerConfig()
            .setTypeClass(Object.class)
            .setImplementation(new ObjectStreamSerializer());
    scfg.add(serializer);
    clientConfig.getSerializationConfig().setSerializerConfigs(scfg);

    instance = HazelcastClient.newHazelcastClient(clientConfig);

    Map<String, ExpiringSession> sessions = instance.getMap(sessionMapName);

    SessionRepository<ExpiringSession> sessionRepository
            = new MapSessionRepository(sessions);
    SessionRepositoryFilter<ExpiringSession> filter
            = new SessionRepositoryFilter<ExpiringSession>(sessionRepository);
    Dynamic fr = sc.addFilter("springSessionFilter", filter);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}

@Override
public void contextDestroyed(ServletContextEvent sce) {
    if (instance != null) {
        instance.shutdown();
    }
}

}

  1. I saw this code connected to the Hazelcast server but not persisting the session. What i doing wrong ?
  • You need to ensure that the Spring Session Filter is registered before anything that commits the response and before anything that creates a session. Does Spring Security work for you? If so, can you enable debugging? For XML configuration you can use for Java Configuration you can use @EnableWebSecurity(debug = true) Then post your logs for when the session is requested. If debug is working, you should see a stacktrace for when the session is created. Include that in the post. – Rob Winch Apr 15 '15 at 01:47
  • @RobWinch, spring security works well. I think the problem is my web.xml file. Because i have two servlet: 1. javax.faces.webapp.FacesServlet 2. org.springframework.web.filter.DelegatingFilterProxy and i dont know how to spring session will create a new session ? (Note: I dont use spring mvc) – Amit Ranjitchi Apr 16 '15 at 13:22
  • Please enable debug on Spring Security and post the stacktrace of when a session is created. This will allow me to see if Spring Session is being included properly. – Rob Winch Apr 16 '15 at 14:24

0 Answers0