HttpSession to remote Infinispan cache - Encoding and Marshalling

994 views
Skip to first unread message

Linda Janse van Rensburg

unread,
Jun 2, 2022, 8:03:12 AM6/2/22
to WildFly
WildFly 24.0.1.Final / Bootable Jar 5.0.2.Final / Infinispan Server 13.0.6.Final
layers: web-server, web-clustering, logging
Very simple war project with 1 servlet that prints the session id and host on the screen.
Project name: SessionHotRod
WAR name: SessionHotRod.war
Bootable jar name: SessionHotRod-bootable.jar

distributable-web.xml:
<distributable-web xmlns="urn:jboss:distributable-web:2.0">
    <session-management name="hotrodSM"/>
</distributable-web>
 
web.xml:
<web-app id="WebApp_ID" version="3.1" …. >  
   <distributable/>              
</web-app>

standalone.xml:
<subsystem xmlns="urn:jboss:domain:distributable-web:2.0" default-session-management="default" default-single-sign-on-management="default">
   <infinispan-session-management name="default" cache-container="web" granularity="SESSION">
       <primary-owner-affinity/>
   </infinispan-session-management>
   <hotrod-session-management name="hotrodSM" remote-cache-container="sessionCache" granularity="SESSION">
       <no-affinity/>
   </hotrod-session-management>
   <infinispan-single-sign-on-management name="default" cache-container="web" cache="sso"/>
   <infinispan-routing cache-container="web" cache="routing"/>
</subsystem>

<subsystem xmlns="urn:jboss:domain:infinispan:13.0">
   <cache-container name="web" default-cache="dist" marshaller="PROTOSTREAM" modules="org.wildfly.clustering.web.infinispan">
      <transport lock-timeout="60000"/>
      <replicated-cache name="sso">
         <locking isolation="REPEATABLE_READ"/>
         <transaction mode="BATCH"/>
         <expiration interval="0"/>
      </replicated-cache>
      <replicated-cache name="routing">
         <expiration interval="0"/>
      </replicated-cache>
      <distributed-cache name="dist">
         <locking isolation="REPEATABLE_READ"/>
         <transaction mode="BATCH"/>
         <expiration interval="0"/>
         <file-store/>
       </distributed-cache>
    </cache-container>
    <remote-cache-container name="sessionCache" default-remote-cluster="infinispan-server-cluster" modules="org.wildfly.clustering.web.hotrod">
       <property name="infinispan.client.hotrod.auth_username">admin</property>
       <property name="infinispan.client.hotrod.auth_password">secret</property>
       <remote-clusters>
          <remote-cluster name="infinispan-server-cluster" socket-bindings="infinispan-server-1"/>
       </remote-clusters>
    </remote-cache-container>
</subsystem>

I'm a bit unsure if I have to set configurations for Encoding & Marshalling or are there some default out of the box configurations.

I had a look at the example: http://www.mastertheboss.com/jboss-frameworks/infinispan/how-to-externalize-http-sessions-on-infinispan/ and cannot see that anything specific gets configured w.r.t encoding and marshalling. (Is this a good example?)

When I startup my application, I see the following 2 warnings in the logs:

13:26:57,294 WARN  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 15) WFLYCLINF0033: Attribute 'marshaller' is configured to use a deprecated value: LEGACY; use one of the following values instead: [JBOSS, PROTOSTREAM]

13:27:00,772 WARN  [org.infinispan.HOTROD] (HotRod-client-async-pool-0) ISPN004005: Error received from the server: org.infinispan.server.hotrod.CacheNotFoundException: Cache with name 'SessionHotRod.war' not found amongst the configured caches

For the first warning I've changed the remote-cache-container config and added marshaller="PROTOSTREAM"
<remote-cache-container name="sessionCache" default-remote-cluster="infinispan-server-cluster" marshaller="PROTOSTREAM" modules="org.wildfly.clustering.web.hotrod">

After I ran my TestServlet, when navigating to the Infinispan Admin Console, I can see the SessionHotRod.war cache. Now if I want to see what is in my cache, surely I have to make some changes to the Encoding/Marshalling configs to be able to see what is inside the cache?

This cache either has no encoding configuration or uses an encoding that the console does not support. You must use HotRod clients to perform read and write operations on this cache.

When I try to navigate into the cahce, I get the following message on the console:
and I get the following message in the Infinispan server logs:
WARN  (blocking-thread--p3-t4) [org.infinispan.encoding.impl.StorageConfigurationManager] ISPN000599: Configuration for cache 'SessionHotRod.war' does not define the encoding for keys or values. If you use operations that require data conversion or queries, you should configure the cache with a specific MediaType for keys or values.

So does this mean you cannot see from the Infinispan Admin Consle what is in your cache when externalizing HttpSession to a remote Infinispan Server? I do understand that the console also needs to know how to unmarshal the HttpSession in order to show what is in the cache. Is this possible?

[I have added a cache template in the Infinispan.xml  that has the media-type application/x-protostream for both the key and the value and changed my hotrod-session-management configuration to use this template
Now when navigating into the cache on the Admin Console , I get Invalid wire type 6 in tag 30]

Paul Ferraro

unread,
Jun 2, 2022, 11:49:34 AM6/2/22
to WildFly
This is a good example.
 
When I startup my application, I see the following 2 warnings in the logs:

13:26:57,294 WARN  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 15) WFLYCLINF0033: Attribute 'marshaller' is configured to use a deprecated value: LEGACY; use one of the following values instead: [JBOSS, PROTOSTREAM]

You'll want this set to PROTOSTREAM.  Note: this is the marshaller preferred by the distributed session manager to marshal the entries it stores in the remote cache.  This is distinct from the marshalling of session attributes - which currently only supports JBoss Marshalling (see https://issues.redhat.com/browse/WFLY-13904).
 
13:27:00,772 WARN  [org.infinispan.HOTROD] (HotRod-client-async-pool-0) ISPN004005: Error received from the server: org.infinispan.server.hotrod.CacheNotFoundException: Cache with name 'SessionHotRod.war' not found amongst the configured caches

For the first warning I've changed the remote-cache-container config and added marshaller="PROTOSTREAM"
<remote-cache-container name="sessionCache" default-remote-cluster="infinispan-server-cluster" marshaller="PROTOSTREAM" modules="org.wildfly.clustering.web.hotrod">

Correct.
 
After I ran my TestServlet, when navigating to the Infinispan Admin Console, I can see the SessionHotRod.war cache. Now if I want to see what is in my cache, surely I have to make some changes to the Encoding/Marshalling configs to be able to see what is inside the cache?

You won't be able to read the cache contents because the requisite ProtoStream schemas/marshallers and key/value classes do not exist on the remote Infinispan server.
 
This cache either has no encoding configuration or uses an encoding that the console does not support. You must use HotRod clients to perform read and write operations on this cache.

When I try to navigate into the cahce, I get the following message on the console:
and I get the following message in the Infinispan server logs:
WARN  (blocking-thread--p3-t4) [org.infinispan.encoding.impl.StorageConfigurationManager] ISPN000599: Configuration for cache 'SessionHotRod.war' does not define the encoding for keys or values. If you use operations that require data conversion or queries, you should configure the cache with a specific MediaType for keys or values.

So does this mean you cannot see from the Infinispan Admin Consle what is in your cache when externalizing HttpSession to a remote Infinispan Server?

Correct.
 
I do understand that the console also needs to know how to unmarshal the HttpSession in order to show what is in the cache. Is this possible?

It might be possible, but it would be extremely cumbersome to do this.
It would involve making all of the requisite ProtoStream marshallers/schemas used by WildFly's distributed session manager as well as the key/value classes themselves available to Infinispan server and ensuring that all the requisite SerializationContextInitializers are registered.  Assuming you could get this working, you would only have access to raw session ID byte[]s and session meta data entries.  You would not be able to read the session attributes themselves, since these are marshalled using JBoss Marshalling and would be completely opaque to infinispan-server without access to JBoss Modules, the deployment module, and the exact JBoss Marshalling configuration used by WildFly.

Nilesh Ratta

unread,
Nov 15, 2022, 11:56:59 AM11/15/22
to WildFly
Hi Team,

I am using Wildlfy 20 and Infinispan server 10.1.8.
I am not able authenticate wildfly server to a secured Infinispan server.
In above mail thread I found this  way to authenticate wildlfy server to an infinispan server:
   <remote-cache-container name="sessionCache" default-remote-cluster="infinispan-server-cluster" modules="org.wildfly.clustering.web.hotrod">
       <property name="infinispan.client.hotrod.auth_username">admin</property>
       <property name="infinispan.client.hotrod.auth_password">secret</property>

But it is not working in wildfly 20 which is having following Infinispan subsystem:
 <subsystem xmlns="urn:jboss:domain:infinispan:10.0">

So kindly suggest me the right way to authenticate.

Paul Ferraro

unread,
Nov 15, 2022, 12:54:05 PM11/15/22
to WildFly
You need to use a more recent version of WildFly (21.0 or later) to connect to a remote Infinispan cluster that requires authentication.

Paul Ferraro

unread,
Nov 15, 2022, 12:57:09 PM11/15/22
to WildFly
Also, in the future, please refrain from replying to an existing thread with an unrelated question - instead, start a new thread so that other users who might have a similar question can more easily find an answer.
Reply all
Reply to author
Forward
0 new messages