Well, it's a bit "complex"...
1st we used a simple mongo-collection only containing documents with two fields: SessionID and binary data which is the serialized session.
This had several disadvantages and it's slow.
As this was not part of our build and it caused trouble with doublicated dependencies and stuff, we decided to rewrite this code.
We use morphium in our productional environment and so we decided to use it to serialize the session as well.
This are some things we had to take care of:
- Morphium relies on certain annotations, so we had to add @Embedded to all objects that were to be serialized using morphium
- The Session-Container needs to be part of the WebApplication, as it relies on user data.
- Hence we had a problem with class path and class loading in the TomcatManager (which obviously runs in a different scope than the webapp). The MorphiumSessionManager was built using reflection and strictly using the classloader of the WebApplicationContext.
The last item did take the longest to implement and to come up with. Acutally, storing into mongo worked fine, but restoring caused problems, as the Object would be instanciated in a differen Class Loader context. Using reflection we could define which classloader to use better.
Nevertheless, the session serialization is now about 10 times as fast as before. Thanks to Mongo!