WildFly 36 SerializationContextInitializer not loading

181 views
Skip to first unread message

Jurij Bilas

unread,
Jul 1, 2025, 5:14:06 AMJul 1
to WildFly
I'm trying to use the wildfly's infinispan cache with PROTOSTREAM marshaller.
In a simple web application, I annotated my key/value classes, created adapters and protostream-processor did its job. The WAR file contains the META-INF/services/org.infinispan.protostream.SerializationContextInitializer file, but it doesn't appear to be loaded by WildFly despite what "High Availability Guide" claims:

"WildFly initializes its ProtoStream marshaller using all instances of org.infinispan.protostream.SerializationContextInitializer that are visible to the deployment classpath. Implementations should be enumerated within a file named: /META-INF/services/org.infinispan.protostream.SerializationContextInitializer"

Is there a trick to this that the documentation fails to mention? Also, it appears that the protostream marshaller cannot be used for heap-memory, it's simply ignored and wildfly falls back to default. 

My cache configuration:
            <cache-container name="myContainer" marshaller="PROTOSTREAM">
                <local-cache name="myCache">
                    <off-heap-memory size="10000000"/>
                    <expiration lifespan="864000000"/>
                </local-cache>
            </cache-container>

Paul Ferraro

unread,
Jul 4, 2025, 7:35:54 AMJul 4
to WildFly
Can you paste your application code that creates your cache instance?

On Tuesday, July 1, 2025 at 10:14:06 AM UTC+1 Jurij Bilas wrote:
I'm trying to use the wildfly's infinispan cache with PROTOSTREAM marshaller.
In a simple web application, I annotated my key/value classes, created adapters and protostream-processor did its job. The WAR file contains the META-INF/services/org.infinispan.protostream.SerializationContextInitializer file, but it doesn't appear to be loaded by WildFly despite what "High Availability Guide" claims:

"WildFly initializes its ProtoStream marshaller using all instances of org.infinispan.protostream.SerializationContextInitializer that are visible to the deployment classpath. Implementations should be enumerated within a file named: /META-INF/services/org.infinispan.protostream.SerializationContextInitializer"

Is there a trick to this that the documentation fails to mention?

 
Also, it appears that the protostream marshaller cannot be used for heap-memory, it's simply ignored and wildfly falls back to default. 

Heap memory does not perform any marshalling of entries.  Why would you expect this?

Jurij Bilas

unread,
Jul 4, 2025, 12:31:06 PMJul 4
to WildFly
public class Data {
@ProtoField(number = 1, type = Type.UINT32)
int id;
@ProtoField(number = 2, type = Type.UINT32)
int date;
@ProtoField(number = 3)
double value;
}

@ProtoSchema(includeClasses = {Data.class},
allowNullFields = true,
syntax = ProtoSyntax.PROTO2)
public interface MyProtoSchema extends GeneratedSchema {
}

@ApplicationScoped
public class InfinispanCacheManager {

@Resource(lookup = "java:jboss/infinispan/container/myContainer")
private EmbeddedCacheManager embeddedManager;

@Override
public <StringData> Cache<String, Data> getCache(String name) {
return 
embeddedManager getCache(name, false);
}
}


This cache manager is then CDI injected in another bean.
One thing I've tried is creating an EmbeddedCacheManager manually without injection, and that works.

Thanks

Paul Ferraro

unread,
Jul 7, 2025, 3:10:23 AMJul 7
to WildFly
From what I can tell, your cache is probably not using the configuration you think it is.
I don't see anything in your application that would force the "myCache" configuration to be defined within the "myContainer" cache container.
Consequently, calls to EmbeddedCacheManager.getCache("myCache") will return a default local cache using Infinispan defaults.

To ensure that a configuration defined within the Infinispan subsystem is available for use within your application you need to either:

1. Add a dependency on this configuration to your application, e.g. by injecting it via @Resource or by defining a <resource-ref/> or <resource-env-ref/> in your deployment descriptor.
   e.g. @Resource(lookup = "java:jboss/infinispan/configuration/myContainer/myCache") Configuration configuration;

2. Inject the cache directly, rather than looking it up via the cache manager, e.g.
   e.g. @Resource(lookup = "java:jboss/infinispan/cache/myContainer/myCache") Cache<String, Data> cache;

Jurij Bilas

unread,
Jul 7, 2025, 5:10:28 AMJul 7
to WildFly
I do have <resource-ref> in the web.xml for every cache defined for myContainer. I also tried injecting Cache instead of EmbeddedCacheManager with the same result. I can confirm that the "myCache" configuration is indeed the one defined for "myContainer" in standalone.xml.

The main difference I see between my project and the test case you mentioned is that I'm using CDI bean and not EJB. My @ApplicationScoped CDI bean is created lazily vs the @Startup annotated EJB in the test case. Could this be the culprit?

Paul Ferraro

unread,
Jul 7, 2025, 8:39:17 AMJul 7
to Jurij Bilas, WildFly
Hmm - the injection should work fine with CDI (this was fixed some time ago).  Thank you for confirming that the cache configuration is the expected one.
Are you getting some kind of exception when reading/writing from/to the cache?
I'm wondering if there is some kind of transcoding issue, since off-heap requires application/x-java-object -> application/octet-stream encoding.

Can you output the values returned by:

cache.getKeyDataConversion().getRequestMediaType()
cache.getKeyDataConversion().getStorageMediaType()
cache.getValueDataConversion().getRequestMediaType()
cache.getValueDataConversion().getStorageMediaType()
--
You received this message because you are subscribed to the Google Groups "WildFly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wildfly+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/wildfly/7f10de17-8ce0-4a1b-a264-5c37672afc18n%40googlegroups.com.

Jurij Bilas

unread,
Jul 7, 2025, 5:14:46 PMJul 7
to WildFly
getRequestMediaType() returns "application/x-java-object", getStorageMediaType() returns "application/x-protostream; agent=wildfly" for both key and value.

The exception I get is "ISPN000615: Unable to unmarshall 'com.iis.datacenter.Data' as a marshaller is not present in the user or global SerializationContext". 
And the reason it isn't present is because the SerializationContextInitializer is never invoked.

Jurij Bilas

unread,
Jul 16, 2025, 5:18:52 PMJul 16
to WildFly
Any other hints how to troubleshoot this? Or possible workarounds? Thanks.

Paul Ferraro

unread,
Jul 18, 2025, 10:25:15 AMJul 18
to Jurij Bilas, WildFly
I've submitted a fix here: https://github.com/wildfly-clustering/wildfly-clustering/commit/0db4faa8a53e27fc36a0a49e140a8eef7defdb33

You could workaround the issue by registering a transcoder that supports "application/x-protostream; agent=wildfly" <-> "application/octet-stream" encoding/decoding.


Jurij Bilas

unread,
Oct 22, 2025, 4:07:49 PMOct 22
to WildFly
Thanks for addressing this!

The generated SerializationContextInitializer is now properly invoked and the custom marshalling appears to work for values.
But for keys that are simple strings cache.put() throws another exception:

org.infinispan.commons.CacheException: class java.lang.String cannot be cast to class org.infinispan.commons.marshall.WrappedBytes (java.lang.String is in module java.base of loader 'bootstrap'; org.infinispan.commons.marshall.WrappedBytes is in unnamed module of loader 'org.infinis...@15.2.6.Final' @1bc21fc7) 

Shouldn't strings be automatically transcoded, like any other common java type?
Reply all
Reply to author
Forward
0 new messages