Search code examples
javaopen-libertysession-cache

Share sessions data between different apps using httpSessionCache and HazelCast in OpenLiberty


Usings the OpenLiberty sessionCache-1.0 feature with HazelCast enables you to easily persist and share session data in a HazelCast in-memory cluster as explained here: https://openliberty.io/guides/sessions.html.

However in this setup session data is stored internally in the maps named: com.ibm.ws.session.attr.[app-context-root] & com.ibm.ws.session.meta.[app-context-root] as indicated here (I don't see the OpenLiberty docs clearly specifying this though)

This prevents different apps (with different context-roots) to share session data since they are writing and reading session data from different named maps.

Is there a way to overwrite this name to enable apps with different context-roots to read write from the same map to share session data?

I was going over the httpSession- and httpSessionCache-properties in the OpenLiberty docs but could not find any attribute supporting such a thing.


Solution

  • To share session between different Web apps within the same EAR, you can use shared-session-context in ibm-application-ext.xml to enable all Web apps use the same session context-root.

    https://www.ibm.com/docs/en/was-liberty/base?topic=configuration-osgiapplication#application-ext

    Here's an example:

    <?xml version="1.0" encoding="UTF-8"?>
    <application-ext version="1.1" 
        xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-application-ext_1_1.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://websphere.ibm.com/xml/ns/javaee">
        
        <shared-session-context value="true"/>
    </application-ext>