Tomcat session persistance after stop/start

I've been using intellij for years for servlet development in tomcat.  But something has always been a mystery to me.

Sometimes with some combinations of Intellij/Tomcat, when I stop and then start tomcat the sessions will be serialized and deserialized so that they will still be valid.   Other times over the years, this doesn't happen.

I've searched the forums and the web, and there is a lot of chatter about this and similar topics, much of it old and seemingly applying to older versions of Intellij/Tomcat.  There is a lot of talk about setting 'reloadable=true' somewhere, but not clear where in server.xml, or some servlet specific xml file that may or may not exist.  I'm not even sure that has anything to do with my particular problem.  I'm not sure if this is tomcat or intellij or just a weird interaction of the two.

Note that I'm not talking about recompiling/redeploying, although that's currently not preserving sessions either for some reason.  I'm talking about stopping tomcat, then starting it again.

This works fine for my app without Intellij. On tomcat servers the sessions persist just fine.

I'm currently running IntelliJ 9.0 Ultimate IU-93.19 and Tomcat 6.0.20.

Where's the magic switch that turns on/off session persistence?

5 comments
Comment actions Permalink

As far as I can see, there is no such switch. In fact, even though my Tomcat serializes sessions to hard disk on shutdown, Idea clears the base directory on startup, so Tomcat cannot restore them.

Here is how it looks like on my computer with an application that serializes a login token to the hard disk, after I shutdown Tomcat from within Idea:

agligor@mbi-gligor ~/Library/Caches/IntelliJIDEA90/tomcat # la tomcat_Unnamed_evolution28d47a36/work/Catalina/localhost/_/
total 104
drwxr-xr-x  4 agligor  staff    136 Jan 28 13:38 .
drwxr-xr-x  7 agligor  staff    238 Jan 28 13:35 ..
-rw-r--r--  1 agligor  staff  51774 Jan 28 13:38 SESSIONS.ser
drwxr-xr-x  4 agligor  staff    136 Jan 28 13:38 wicketFilter-filestore


The file SESSIONS.ser contains the serialized data. And here is what happens when I start Tomcat from within Idea again:

agligor@mbi-gligor ~/Library/Caches/IntelliJIDEA90/tomcat # la tomcat_Unnamed_evolution28d47a36/work/Catalina/localhost/_/
ls: tomcat_Unnamed_evolution28d47a36/work/Catalina/localhost/_/: No such file or directory


As a workaround, I copied SESSIONS.ser to a different folder, and copy the file back to its place early during Tomcat startup.

0
Comment actions Permalink

That's helpful..  perhaps as a hack I might even right something in my servet startup event to do the copy automatically..  I just have to beleive there is a straightforward way to accomplish this somehow though..

My latest mystery on this topic:  My 9.0.1 install no longer shuts down tomcat when I stop the debugger.  I see it call the 'catalina.bat stop' script, but then the JVM is immediately halted and non of the context shutdown events get a chance to fire..  Really really annoying.  I have no idea if this is a bug, or I inadvertantly did a setting somewhere for this.

0
Comment actions Permalink

As of 9.0 (I think) there is a "Shutdown Application Server" button just under the "Stop" button. The "Stop" button kills Tomcat, whereas the "Shutdown" button shuts down cleanly.

0
Comment actions Permalink

Try adding this to either tomcat's server.mxl or in {tomcat}/conf/context.xml (see link below to see where exactly it should appear):

<Manager className="org.apache.catalina.session.PersistentManager">
         <Store className="org.apache.catalina.session.FileStore" directory="YOUR_DESIRED_DIRECTORY"/>
</Manager
>

This used to work for me, but hasn't recently.  However, you may have better luck -- my problem might be with the application with which I'm working.

Look for PersistentManager on the tomcat docs for further details.  As a matter of fact, I see there's a system property that is also required -- maybe that explains my problem.

I'd be curious if this works for you -- let me know!

~kc

** Updated **

I observe that even setting the filestore's directory, serialized sessions get removed, presumably by IDEA.  If that XML snippet doesn't work for you, there's always changing tomcat startup and shutdown scripts to copy the files.  See the Startup/Connection tab of your idea configuration.

0
Comment actions Permalink

adriang wrote:

As of 9.0 (I think) there is a "Shutdown Application Server" button just under the "Stop" button. The "Stop" button kills Tomcat, whereas the "Shutdown" button shuts down cleanly.


That's very helpful.  I click the stop button a zillion times a day but I never actually noticed the shutdown button.

But now it makes me somewhat more frustrated.  The stop button is going to get hit a lot accidently, and there seems no way to modify that button bar.  Worse yet, the Run dialog has no shutdown button, and the stop button seems to shutdown, so the Run/Debug dialogs are inconsistent.

0

Please sign in to leave a comment.