Search in sources :

Example 11 with EncoderRegistry

use of org.infinispan.marshall.core.EncoderRegistry in project infinispan by infinispan.

the class LifecycleManager method buildQuerySerializers.

private QuerySerializers buildQuerySerializers(ComponentRegistry cr, MediaType storageMediaType) {
    EncoderRegistry encoderRegistry = cr.getGlobalComponentRegistry().getComponent(EncoderRegistry.class);
    QuerySerializers querySerializers = new QuerySerializers();
    DefaultQuerySerializer defaultQuerySerializer = new DefaultQuerySerializer(encoderRegistry);
    querySerializers.addSerializer(MediaType.MATCH_ALL, defaultQuerySerializer);
    if (encoderRegistry.isConversionSupported(storageMediaType, APPLICATION_JSON)) {
        Transcoder jsonStorage = encoderRegistry.getTranscoder(APPLICATION_JSON, storageMediaType);
        querySerializers.addSerializer(APPLICATION_JSON, new JsonQuerySerializer(storageMediaType, jsonStorage));
    }
    return querySerializers;
}
Also used : EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) Transcoder(org.infinispan.commons.dataconversion.Transcoder)

Example 12 with EncoderRegistry

use of org.infinispan.marshall.core.EncoderRegistry in project infinispan by infinispan.

the class CacheResourceV2 method negotiateEntryMediaType.

private MediaType negotiateEntryMediaType(AdvancedCache<?, ?> cache, boolean forKey) {
    MediaType storage = forKey ? cache.getKeyDataConversion().getStorageMediaType() : cache.getValueDataConversion().getStorageMediaType();
    EncoderRegistry encoderRegistry = invocationHelper.getEncoderRegistry();
    boolean encodingDefined = !MediaType.APPLICATION_UNKNOWN.equals(storage);
    boolean jsonSupported = encodingDefined && encoderRegistry.isConversionSupported(storage, APPLICATION_JSON);
    boolean textSupported = encodingDefined && encoderRegistry.isConversionSupported(storage, TEXT_PLAIN);
    if (textSupported)
        return TEXT_PLAIN;
    if (jsonSupported)
        return APPLICATION_JSON;
    if (encodingDefined)
        return storage.withEncoding("hex");
    return APPLICATION_OCTET_STREAM.withEncoding("hex");
}
Also used : EncoderRegistry(org.infinispan.marshall.core.EncoderRegistry) MediaType(org.infinispan.commons.dataconversion.MediaType) MediaTypeUtils.negotiateMediaType(org.infinispan.rest.resources.MediaTypeUtils.negotiateMediaType)

Aggregations

EncoderRegistry (org.infinispan.marshall.core.EncoderRegistry)12 AdvancedCache (org.infinispan.AdvancedCache)5 Cache (org.infinispan.Cache)3 MediaType (org.infinispan.commons.dataconversion.MediaType)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)3 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)3 CacheManagerCallable (org.infinispan.test.CacheManagerCallable)3 Test (org.testng.annotations.Test)3 Arrays (java.util.Arrays)2 Map (java.util.Map)2 Optional (java.util.Optional)2 ClassAllowList (org.infinispan.commons.configuration.ClassAllowList)2 Transcoder (org.infinispan.commons.dataconversion.Transcoder)2 GenericJBossMarshaller (org.infinispan.jboss.marshalling.commons.GenericJBossMarshaller)2 AbstractInfinispanTest (org.infinispan.test.AbstractInfinispanTest)2 Person (org.infinispan.test.data.Person)2 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1 RemovalListener (com.github.benmanes.caffeine.cache.RemovalListener)1 Closeable (java.io.Closeable)1