0

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.

Jan Snelders
  • 203
  • 2
  • 5

2 Answers2

0

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>
  • Thanks Allan for your suggestion. The web apps for which I would like to enable this are actually not in the same ear. It are completely separate deployments (running in their own docker container). I just tested that once I modify the apps to identical context-roots, session-persistence sharing using OpenLiberty sessionCache-1.0 feature with HazelCast actually works fine. However I would like to be able to do this without modifying the context-roots of my deployments. – Jan Snelders Nov 19 '21 at 16:36
0

Sharing session data across different apps is forbidden by the spec:

HttpSession objects must be scoped at the application (or servlet context) level. [...] the object referenced, including the attributes in that object, must never be shared between contexts by the container.

So if you want to share some data between different apps, you have to create separate cache, not related to the sessions. You can also use Hazelcast for it, just not the session cache.

If all apps for example needs to share data that is related to given user, user login could be a key in the cache store.

Gas
  • 17,601
  • 4
  • 46
  • 93