Spring DevTools persistent session empty session map - spring-boot

I am trying to make Spring session persistence work but so far no luck.
So I start the app, do log in, change Java code to force restart and session is lost after that.
Enabled session persistence using server.servlet.session.persistent=true.
I see this property is picked up, and Tomcat is configured properly.
After some debugging I found out that the doUnload() method in org.apache.catalina.session.StandardManager is called properly but the session map is empty!
This happens in https://github.com/Oreste-Luci/apache-tomcat-8.0.26-src/blob/05aeff976f6a75346c95cf6d3a9c8add8b9cb0bc/java/org/apache/catalina/session/StandardManager.java#L338.
Any idea why this is happening? I did log in so I expect session to be created...
Spring Boot 2.1.1.RELEASE, Tomcat started at same version

Related

Cannot find a working configuration for Http Session replication in Grails 4

I wanted to run my Grails application (version 4.0.4) in a cluster. I tried to apply Hazelcast to replicate the HTTP session across the nodes/instances but somehow I couldn’t override/replace the SessionRepository bean that Grails uses with the Hazelcast implementation.
My working configuration in Spring Boot is: I declare the Hazelcast bean and annotate the Application with #EnableHazelcastHttpSession which in turn introduces the new SessionRepository from Hazelcast.
But I couldn’t make this configuration work in Grails and override the SessionRepository. (Although the app starts, it acts very strange.)
Any ideas?
Or do you suggest an alternative approach to implement a distributed session in Grails? How did you replicate session from your past experience?
(P.S The reason I chose Hazelcast is, since it is a distributed cache which can be embedded with the application itself, I can avoid dependency on external service such as Redis, to run the app. That is part of the requirement).
Thank you.

Adding HttpSession Object to Infinispan cache

We have started using infinispan cache with wildfly 13 in our web application. The web application is deployed in wildfly domain mode in a cluster of two node with one acting as master and the other as slave. In the application we have an admin feature, where the admin can terminate a user.
So what we want to do is add session objects to Infinispan cache and retrieve it and terminate it when required. I am aware that HttpSession object is not serializable hence it cannot be added to cache but every attribute added to the session object is serilizable so my question is, is there a workaround for the issue? Because right now we get a NotSerializable error when I try to add session to cache and it's also no longer possible to retrieve session from sessionId and terminate it due to security reasons.
There is no need to manually interact with the Infinispan cache: WildFly transparently supports full http session clustering with Infinispan. See https://docs.jboss.org/author/display/WFLY10/High+Availability+Guide

How to disable Atomikos logfile when running Spring Boot with Atomikos JTA

I am using Spring Boot with Atomikos with embeded undertow server.I will be running my application in docker as a executable jar.We are writing all our logs as Sysout basically we are flushing and not writing any log files.But Atomikos is creating 3 log files when start and run application under my working directory.
How to disable creation of this log files. We should not create any physical log files in Disk.
or
Is there any way I can make these logs will be written in console instead of creating physical file.
Tried below configuration but it's not working.
com:
atomikos:
icatch:
enable_logging=false
You should run with -Dcom.atomikos.icatch.enable_logging=false as Atomikos itself does not read your application.yml so it will not read properties from there. Spring doesn't set this property either. A bit warning though, right from Atomikos documentation:
Specifies if disk logging should be enabled or not. Defaults to true.
It is useful for JUnit testing, or to profile code without seeing the
transaction manager's activity as a hot spot but this should never be
disabled on production or data integrity cannot be guaranteed.
Transaction logs are as important as data as they're used to recover from failures.

Spring Application Context Initialization

In my Spring Application, at the time of context Initialization. The DB is not available, it will come up after some time (Due to DB redundancy). In this scenario, my spring application initialization should be delayed or the application should do retry for DB connectivity. How to achieve the same via Spring.
Srirama.
I'd suggest investigating the ApplicationContextInitializer. It is meant to be used for setting up your context before most of the magic of spring initialization happens.
I'm not sure if it is designed for your use case, but no beans are initialized when the initialize method is called during startup.
The example provided in the link deals with properties, but I see no reason why you should not create your own manually created connection and wait for it's readiness.
Thanks for the reply.
My application is initialized by means of C3P0. Here C3P0, is trying to reconnect to DB only for 30 times (the default configuration for acquireRetryAttempts) and after that it is saying failed to create the application beans.
Changed the configuration for acquireRetryAttempts to -1, so that C3P0 is retrying indefinitely till the DB connection is successful. Basically my app. initialization should be delayed till the DB comes up.
Srirama.

Jetty / Tomcat session saving

Where does Tomcat or Jetty saves the sessionids (without session persistence configuration)? Does it go anywhere in the file system, or does it stay just in memory?
Tomcat uses the StandardManager by default to manage it's session data. During run-time this data is not persisted to a store and exists only in memory. When you shutdown Tomcat it will try to persist all the session data to $TOMCAT_HOME/work/Catalina///SESSIONS.ser. Tomcat will try to reload these session on next startup and it will also delete the SESSIONS.ser file after a successful start. If your server dies or you execute a kill -9 this session data will be lost.
Documentation for the StandardManager is here http://tomcat.apache.org/tomcat-5.5-doc/config/manager.html
I don't know Jetty very well but Jetty does not have any persistence by default so the sessions are in memory. You can enable persistence if you want and its documented here docs.codehaus.org/display/JETTY/Persisting+Sessions.
Hope this helps.

Resources