Search in sources :

Example 1 with MarshallerRegistry

use of org.infinispan.client.hotrod.impl.MarshallerRegistry in project infinispan by infinispan.

the class MarshallerPerCacheTest method testMarshallerPerCache.

@Test
public void testMarshallerPerCache() throws IOException, InterruptedException {
    MarshallerRegistry marshallerRegistry = remoteCacheManager.getMarshallerRegistry();
    assertMarshallerUsed(CACHE_DEFAULT, marshallerRegistry.getMarshaller(APPLICATION_PROTOSTREAM));
    assertMarshallerUsed(CACHE_TEXT, new CustomValueMarshaller());
    assertMarshallerUsed(CACHE_JAVA_SERIALIZED, marshallerRegistry.getMarshaller(APPLICATION_SERIALIZED_OBJECT));
}
Also used : MarshallerRegistry(org.infinispan.client.hotrod.impl.MarshallerRegistry) Test(org.testng.annotations.Test) SingleHotRodServerTest(org.infinispan.client.hotrod.test.SingleHotRodServerTest)

Example 2 with MarshallerRegistry

use of org.infinispan.client.hotrod.impl.MarshallerRegistry in project infinispan by infinispan.

the class SpringRemoteCacheManager method configureMarshallers.

private void configureMarshallers(RemoteCacheManager nativeCacheManager) {
    MarshallerRegistry marshallerRegistry = nativeCacheManager.getMarshallerRegistry();
    // Java serialization support
    JavaSerializationMarshaller serializationMarshaller = (JavaSerializationMarshaller) marshallerRegistry.getMarshaller(MediaType.APPLICATION_SERIALIZED_OBJECT);
    if (serializationMarshaller == null) {
        // Register a JavaSerializationMarshaller if it doesn't exist yet
        // Because some session attributes are always marshalled with Java serialization
        serializationMarshaller = new JavaSerializationMarshaller();
        marshallerRegistry.registerMarshaller(serializationMarshaller);
    }
    // Extend deserialization allow list
    ClassAllowList serializationAllowList = new ClassAllowList();
    serializationAllowList.addClasses(NullValue.class);
    serializationAllowList.addRegexps("java.util\\..*", "org.springframework\\..*");
    serializationMarshaller.initialize(serializationAllowList);
    // Protostream support
    ProtoStreamMarshaller protoMarshaller = (ProtoStreamMarshaller) marshallerRegistry.getMarshaller(MediaType.APPLICATION_PROTOSTREAM);
    if (protoMarshaller == null) {
        try {
            protoMarshaller = new ProtoStreamMarshaller();
            marshallerRegistry.registerMarshaller(protoMarshaller);
            // Apply the serialization context initializers in the configuration first
            SerializationContext ctx = protoMarshaller.getSerializationContext();
            for (SerializationContextInitializer sci : nativeCacheManager.getConfiguration().getContextInitializers()) {
                sci.registerSchema(ctx);
                sci.registerMarshallers(ctx);
            }
        } catch (NoClassDefFoundError e) {
        // Ignore the error, the protostream dependency is missing
        }
    }
    if (protoMarshaller != null) {
        // Apply our own serialization context initializers
        SerializationContext ctx = protoMarshaller.getSerializationContext();
        addSessionContextInitializerAndMarshaller(ctx, serializationMarshaller);
    }
}
Also used : SerializationContext(org.infinispan.protostream.SerializationContext) MarshallerRegistry(org.infinispan.client.hotrod.impl.MarshallerRegistry) ProtoStreamMarshaller(org.infinispan.commons.marshall.ProtoStreamMarshaller) ClassAllowList(org.infinispan.commons.configuration.ClassAllowList) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer) JavaSerializationMarshaller(org.infinispan.commons.marshall.JavaSerializationMarshaller)

Aggregations

MarshallerRegistry (org.infinispan.client.hotrod.impl.MarshallerRegistry)2 SingleHotRodServerTest (org.infinispan.client.hotrod.test.SingleHotRodServerTest)1 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)1 JavaSerializationMarshaller (org.infinispan.commons.marshall.JavaSerializationMarshaller)1 ProtoStreamMarshaller (org.infinispan.commons.marshall.ProtoStreamMarshaller)1 SerializationContext (org.infinispan.protostream.SerializationContext)1 SerializationContextInitializer (org.infinispan.protostream.SerializationContextInitializer)1 Test (org.testng.annotations.Test)1